加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Lua学习笔记(一)

发布时间:2020-12-14 22:24:42 所属栏目:大数据 来源:网络整理
导读:lua是啥东西就不说了。 ? 1、下载lua,目前版本5.1 wget http://www.lua.org/ftp/lua-5.1.tar.gz ? 2、解压 tar -xzf lua-5.1.tar.gz ? 3、编译 make 不行,提示信息如下: Please do ?? make PLATFORM where PLATFORM is one of these: ?? aix ansi bsd gen

lua是啥东西就不说了。

?

1、下载lua,目前版本5.1

wget http://www.lua.org/ftp/lua-5.1.tar.gz

?

2、解压

tar -xzf lua-5.1.tar.gz

?

3、编译

make

不行,提示信息如下:

Please do
?? make PLATFORM
where PLATFORM is one of these:
?? aix ansi bsd generic linux macosx mingw posix solaris
See INSTALL for complete instructions.
原来是这样用:

make linux

?

4、安装

make install

安装时,将liblua.a拷贝到/usr/local/lib中,将lua.h等头文件拷贝到/usr/local/include中。

?

5、编写第一个lua程序:luatest.c

?

#include <stdio.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>

/* Lua解释器指针 */
lua_State* L;

int main ( int argc,char *argv[] )
{???
??? if (argc == 1)
??? {
??????? printf("usage: %s filename/n",argv[0]);
??????? printf("filename -- lua script file/n");
??????? return 0;
??? }

??? L = lua_open();?????????????????????????????????? /* 初始化Lua */
??? luaL_openlibs(L);? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? /* 载入Lua基本库 */

??? luaL_dofile(L,argv[1]);?? ? ? ? ? ? ? ? ? ? ? /* 运行脚本 */
??? lua_close(L);??? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? /* 清除Lua */
??? printf( "Press enter to exit... /n" );?? ??? /* 暂停 */???
??? getchar();???
??? return 0;
}

?

6、编译luatest.c

gcc luatest.c -lm -llua -ldl -o luatest

注意:

1) luatest.c 一定要放在前面,否则链接的时候会出错,原因不明。

2)-lm是数学库,liblua调用了数学库

?

7、编写lua脚本:hello.lua

-- simple test
print "Hello,World!"

注意:--simple test是注释

?

8、执行脚本:

luatest hello.lua

输出:

Hello,World!
Press enter to exit...

?

ok,搞定。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读