lua c api

时间:2024-09-02 10:04:32
#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[];
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, , , );
if (error)
{
fprintf(stderr, "%s", lua_tostring(L, -));
lua_pop(L, );
}
}
lua_close(L);
return ;
}