Lua 5.2 C API中的语法如何改写才能形成一句长尾词的?
- 内容介绍
- 文章标签
- 相关推荐
本文共计328个文字,预计阅读时间需要2分钟。
在《Lua编程》一书中提供的示例,仅适用于Lua 5.1及以上版本。执行此操作的步骤如下:
1. 确保使用Lua 5.1或更高版本。
2.编写代码,参考书中的示例。
3.运行代码,观察结果。
我试图编译 Programming in Lua书中提供的示例但仅适用于lua 5.1,在5.2上执行此操作的步骤是什么?
这是我正在使用的代码
#include <stdio.h> #include <string.h> #include <lua.h> #include <lauxlib.h> #include <lualib.h> int main (void) { char buff[256]; int error; lua_State *L = lua_open(); /* opens Lua */ luaL_openlibs(L); while (fgets(buff, sizeof(buff), stdin) != NULL) { error = luaL_loadbuffer(L, buff, strlen(buff), "line") || lua_pcall(L, 0, 0, 0); if (error) { fprintf(stderr, "%s", lua_tostring(L, -1)); lua_pop(L, 1); /* pop error message from the stack */ } } lua_close(L); return 0; }
用gcc test01.c -I /usr/include / lua5.2 -L /usr/lib / x86_64-linux-gnu -llua5.2编译后出现以下错误:
test01.c: In function ‘main’: test01.c:10:18: warning: initialization makes pointer from integer without a cas t [enabled by default] lua_State *L = lua_open(); /* opens Lua */ ^ /tmp/ccyPRlV3.o: In function `main': test01.c:(.text+0x21): undefined reference to `lua_open' collect2: error: ld returned 1 exit status
先感谢您.
luaopen()不再使用,它被luaL_newstate取代,你可以使用luaL_newstate创建一个具有标准分配函数的状态:
lua_State *L = luaL_newstate(); /* opens Lua */ luaL_openlibs(L); /* opens the standard libraries */
此API已更改since Lua 5.1
本文共计328个文字,预计阅读时间需要2分钟。
在《Lua编程》一书中提供的示例,仅适用于Lua 5.1及以上版本。执行此操作的步骤如下:
1. 确保使用Lua 5.1或更高版本。
2.编写代码,参考书中的示例。
3.运行代码,观察结果。
我试图编译 Programming in Lua书中提供的示例但仅适用于lua 5.1,在5.2上执行此操作的步骤是什么?
这是我正在使用的代码
#include <stdio.h> #include <string.h> #include <lua.h> #include <lauxlib.h> #include <lualib.h> int main (void) { char buff[256]; int error; lua_State *L = lua_open(); /* opens Lua */ luaL_openlibs(L); while (fgets(buff, sizeof(buff), stdin) != NULL) { error = luaL_loadbuffer(L, buff, strlen(buff), "line") || lua_pcall(L, 0, 0, 0); if (error) { fprintf(stderr, "%s", lua_tostring(L, -1)); lua_pop(L, 1); /* pop error message from the stack */ } } lua_close(L); return 0; }
用gcc test01.c -I /usr/include / lua5.2 -L /usr/lib / x86_64-linux-gnu -llua5.2编译后出现以下错误:
test01.c: In function ‘main’: test01.c:10:18: warning: initialization makes pointer from integer without a cas t [enabled by default] lua_State *L = lua_open(); /* opens Lua */ ^ /tmp/ccyPRlV3.o: In function `main': test01.c:(.text+0x21): undefined reference to `lua_open' collect2: error: ld returned 1 exit status
先感谢您.
luaopen()不再使用,它被luaL_newstate取代,你可以使用luaL_newstate创建一个具有标准分配函数的状态:
lua_State *L = luaL_newstate(); /* opens Lua */ luaL_openlibs(L); /* opens the standard libraries */
此API已更改since Lua 5.1

