Lua学习笔记(一)

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,搞定。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值