小编roc*_*cks的帖子

lua 5.2 C api中的语法更改

我试图编译" 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;
}
Run Code Online (Sandbox Code Playgroud)

编译后gcc test01.c -I/usr/include/lua5.2 -L/usr/lib/x86_64-linux-gnu …

c lua

4
推荐指数
1
解决办法
3200
查看次数

标签 统计

c ×1

lua ×1