#include #include "cctk.h" extern "C" const char *Lua_function_TestLua2_LuaTest2_Hello; CCTK_INT lua_LanguageCall_Lua(const CCTK_POINTER codestring, CCTK_STRING name) { CCTK_INFO("Called LanguageCall_Lua\n"); // create new Lua state lua_State *lua_state; lua_state = luaL_newstate(); // load Lua libraries static const luaL_Reg lualibs[] = { { "base", luaopen_base }, { NULL, NULL} }; const luaL_Reg *lib = lualibs; for(; lib->func != NULL; lib++) { lib->func(lua_state); lua_settop(lua_state, 0); } // run the Lua script int status = luaL_loadstring(lua_state, (const char*)codestring); if (status != LUA_OK) { CCTK_ERROR("Loading Lua code failed"); } lua_pcall(lua_state, 0, LUA_MULTRET, 0); status = luaL_loadstring(lua_state, (std::string(name)+"()").c_str()); if (status != LUA_OK) { CCTK_ERROR("Running Lua code failed"); } lua_pcall(lua_state, 0, LUA_MULTRET, 0); // close the Lua state lua_close(lua_state); return 0; }