锁定老帖子 主题:编程语言 Lua
精华帖 (0) :: 良好帖 (10) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-03-28
最后修改:2009-03-28
概述
Lua 是一个自由软件,它的使用许可决定了对它的使用过程一般没有任何保证。
清单 2. 一个简单的 Lua 解释器 1 #include 2 #include 3 #include 4 #include 5 6 int main (void) { 7 char buff[256]; 8 int error; 9 lua_State *L = lua_open(); /* opens Lua */ 10 luaopen_base(L); /* opens the basic library */ 11 luaopen_table(L); /* opens the table library */ 12 luaopen_io(L); /* opens the I/O library */ 13 luaopen_string(L); /* opens the string lib. */ 14 luaopen_math(L); /* opens the math lib. */ 15 16 while (fgets(buff, sizeof(buff), stdin) != NULL) { 17 error = luaL_loadbuffer(L, buff, strlen(buff), "line") || 18 lua_pcall(L, 0, 0, 0); 19 if (error) { 20 fprintf(stderr, "%s", lua_tostring(L, -1)); 21 lua_pop(L, 1); /* pop error message from the stack */ 22 } 23 } 24 25 lua_close(L); 26 return 0; 27 }
.. if (luaL_loadfile(L, filename) || lua_pcall(L, 0, 0, 0)) error(L, "cannot run configuration file: %s", lua_tostring(L, -1)); lua_getglobal(L, "width"); lua_getglobal(L, "height"); .. width = (int) lua_tonumber(L, -2); height = (int) lua_tonumber(L, -1); ..
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2009-03-28
最后修改:2009-03-28
个人以为加入 CWDG 写山口山插件,是最好的学习途径之一 ……
另外 scite 也嵌入了 lua ,其源代码也很值得学习。 |
|
返回顶楼 | |
发表时间:2009-04-02
最后修改:2009-04-02
写山口山的插件确实非常快的学习lua
以前就改过 |
|
返回顶楼 | |
发表时间:2009-04-09
号称最快的脚本语言,不过除了嵌入,似乎也没什么地方能用到。
话说,LUA跟Python有啥关系的说? |
|
返回顶楼 | |
发表时间:2009-04-22
学起来简单的难以置信,用起来麻烦的难以置信。
鉴定完毕。 |
|
返回顶楼 | |
浏览 8321 次