forked from mirror/openmw-tes3mp
[Server] Add sandboxed import() function
This commit is contained in:
parent
29cb51cdce
commit
062d6a1824
1 changed files with 11 additions and 0 deletions
|
@ -21,6 +21,16 @@ sol::table str_split(const std::string &str, const sol::object &sepObj, sol::thi
|
||||||
return tbl;
|
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)
|
void LuaUtils::Init(LuaState &lua)
|
||||||
{
|
{
|
||||||
sol::table strTable = (*lua.getState())["string"];
|
sol::table strTable = (*lua.getState())["string"];
|
||||||
|
@ -28,4 +38,5 @@ void LuaUtils::Init(LuaState &lua)
|
||||||
throw std::runtime_error("string library not initialized");
|
throw std::runtime_error("string library not initialized");
|
||||||
|
|
||||||
strTable.set_function("split", &str_split);
|
strTable.set_function("split", &str_split);
|
||||||
|
lua.getState()->set_function("import", &import);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue