lua: uidocuments sub-environment

This commit is contained in:
MihailRis
2024-02-11 23:56:24 +03:00
parent 4ce46f34bf
commit e4f7315cc3
9 changed files with 31 additions and 16 deletions
+8 -2
View File
@@ -228,7 +228,7 @@ const std::string lua::LuaState::storeAnonymous() {
return funcName;
}
int lua::LuaState::createEnvironment() {
int lua::LuaState::createEnvironment(int parent) {
int id = nextEnvironment++;
// local env = {}
@@ -236,7 +236,13 @@ int lua::LuaState::createEnvironment() {
// setmetatable(env, {__index=_G})
lua_createtable(L, 0, 1);
lua_pushvalue(L, LUA_GLOBALSINDEX);
if (parent == 0 || true) {
lua_pushvalue(L, LUA_GLOBALSINDEX);
} else {
if (pushenv(parent) == 0) {
lua_pushvalue(L, LUA_GLOBALSINDEX);
}
}
lua_setfield(L, -2, "__index");
lua_setmetatable(L, -2);
+1 -1
View File
@@ -51,7 +51,7 @@ namespace lua {
bool rename(const std::string& from, const std::string& to);
void remove(const std::string& name);;
void createFuncs();
int createEnvironment();
int createEnvironment(int parent);
void removeEnvironment(int id);
const std::string storeAnonymous();
};
+2 -2
View File
@@ -91,8 +91,8 @@ wstringconsumer scripting::create_wstring_consumer(
};
}
std::unique_ptr<Environment> scripting::create_environment() {
return std::make_unique<Environment>(state->createEnvironment());
std::unique_ptr<Environment> scripting::create_environment(int parent) {
return std::make_unique<Environment>(state->createEnvironment(parent));
}
void scripting::on_world_load(Level* level, BlocksController* blocks) {
+1 -1
View File
@@ -51,7 +51,7 @@ namespace scripting {
const std::string& file="<string>"
);
std::unique_ptr<Environment> create_environment();
std::unique_ptr<Environment> create_environment(int parent=0);
void on_world_load(Level* level, BlocksController* blocks);
void on_world_save();