lua 5.2 C api中的语法更改

lua 5.2 C api中的语法更改,第1张

概述我试图编译 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 buf 我试图编译 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);    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 cast [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

总结

以上是内存溢出为你收集整理的lua 5.2 C api中的语法更改全部内容,希望文章能够帮你解决lua 5.2 C api中的语法更改所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1231339.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存