ReturnCode State::registerFunction(Function function, const std::string &name) { MSS_BEGIN(ReturnCode); CHECK_AND_LOCK(pimpl_); lua_pushcfunction(s, (lua_CFunction)function); lua_setglobal(s, name.c_str()); MSS_END(); }
ReturnCode State::execute(const std::string &code) { MSS_BEGIN(ReturnCode); CHECK_AND_LOCK(pimpl_); MSS(luaL_loadstring(s, code.c_str()) == 0, CompileError); MSS(lua_pcall(s, 0, 0, 0) == 0, RuntimeError); MSS_END(); }
ReturnCode State::get(long &v, const std::string &name) const { MSS_BEGIN(ReturnCode); CHECK_AND_LOCK(pimpl_); L(lua_gettop(s)); lua_getglobal(s, name.c_str()); L(lua_gettop(s)); MSS((bool)lua_isnumber(s, -1)); L(lua_gettop(s)); v = lua_tointeger(s, -1); L(lua_gettop(s)); lua_pop(s, 1); L(lua_gettop(s)); MSS_END(); }
ReturnCode State::execute(const string &code, string &err) { MSS_BEGIN(ReturnCode); CHECK_AND_LOCK(pimpl_); if (luaL_loadstring(s, code.c_str()) != 0) { err = lua_tostring(s, -1); MSS_L(CompileError); } err.clear(); if (lua_pcall(s, 0, 0, 0) != 0) { err = lua_tostring(s, -1); MSS_L(RuntimeError); } err.clear(); MSS_END(); }