[Server] Add sandboxed import() function

new-script-api
Koncord 7 years ago
parent 29cb51cdce
commit 062d6a1824

@ -21,6 +21,16 @@ sol::table str_split(const std::string &str, const sol::object &sepObj, sol::thi
return tbl;
}
sol::object import(const std::string &name, sol::this_state ts, sol::this_environment te)
{
sol::state_view state(ts);
sol::environment env(te);
sol::function res = state.load_file(name);
sol::set_environment(env, res);
return res.call();
}
void LuaUtils::Init(LuaState &lua)
{
sol::table strTable = (*lua.getState())["string"];
@ -28,4 +38,5 @@ void LuaUtils::Init(LuaState &lua)
throw std::runtime_error("string library not initialized");
strTable.set_function("split", &str_split);
lua.getState()->set_function("import", &import);
}

Loading…
Cancel
Save