#include <stdio.h>
#include <string.h>
extern "C"{
    #include <lua.h>
    #include <lauxlib.h>
    #include <lualib.h>
}
#pragma comment(lib,"lua.lib") 
int main()
{
    char buff[256];
    int error;
    lua_State* L = luaL_newstate();
    luaopen_base(L);
    luaopen_table(L);
    luaopen_io(L);
    luaopen_string(L);
    luaopen_math(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);
        }
    }
    lua_close(L);
    return 0;
}

 

相关文章:

  • 2021-08-20
  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2022-12-23
  • 2021-08-03
  • 2022-12-23
猜你喜欢
  • 2021-06-04
  • 2022-12-23
  • 2022-02-14
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案