lua: added toml library + content menu fix
This commit is contained in:
@@ -176,27 +176,27 @@ const std::string lua::LuaState::storeAnonymous() {
|
||||
return funcName;
|
||||
}
|
||||
|
||||
void lua::LuaState::initNamespace() {
|
||||
void lua::LuaState::initEnvironment() {
|
||||
lua_getglobal(L, "_G");
|
||||
lua_setfield(L, -1, ":G");
|
||||
}
|
||||
|
||||
int lua::LuaState::createNamespace() {
|
||||
int id = nextNamespace++;
|
||||
int lua::LuaState::createEnvironment() {
|
||||
int id = nextEnvironment++;
|
||||
|
||||
if (currentNamespace != 0) {
|
||||
setNamespace(0);
|
||||
if (currentEnvironment != 0) {
|
||||
setEnvironment(0);
|
||||
}
|
||||
|
||||
lua_createtable(L, 0, 0);
|
||||
initNamespace();
|
||||
initEnvironment();
|
||||
setglobal("_N"+util::mangleid(id));
|
||||
|
||||
setNamespace(id);
|
||||
setEnvironment(id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void lua::LuaState::setNamespace(int id) {
|
||||
void lua::LuaState::setEnvironment(int id) {
|
||||
if (id == 0) {
|
||||
getglobal(":G");
|
||||
lua_setfenv(L, -1);
|
||||
@@ -205,7 +205,7 @@ void lua::LuaState::setNamespace(int id) {
|
||||
lua_getfield(L, -1, ("_N"+util::mangleid(id)).c_str());
|
||||
if (lua_isnil(L, -1)) {
|
||||
lua_pop(L, -1);
|
||||
throw luaerror("namespace "+std::to_string(id)+" was not found");
|
||||
throw luaerror("environment "+std::to_string(id)+" was not found");
|
||||
}
|
||||
lua_setfenv(L, -1);
|
||||
}
|
||||
|
||||
@@ -16,11 +16,11 @@ namespace lua {
|
||||
|
||||
class LuaState {
|
||||
lua_State* L;
|
||||
int nextNamespace = 1;
|
||||
int currentNamespace = 0;
|
||||
int nextEnvironment = 1;
|
||||
int currentEnvironment = 0;
|
||||
|
||||
void logError(const std::string& text);
|
||||
void initNamespace();
|
||||
void initEnvironment();
|
||||
public:
|
||||
LuaState();
|
||||
~LuaState();
|
||||
@@ -44,8 +44,8 @@ namespace lua {
|
||||
bool rename(const std::string& from, const std::string& to);
|
||||
void remove(const std::string& name);;
|
||||
void createFuncs();
|
||||
int createNamespace();
|
||||
void setNamespace(int id);
|
||||
int createEnvironment();
|
||||
void setEnvironment(int id);
|
||||
|
||||
const std::string storeAnonymous();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user