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,搞定。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。