| 138 | //============================================================================// |
| 139 | |
| 140 | bool HubLink::createLua(const std::string& code) { |
| 141 | setupCallInMaps(); |
| 142 | |
| 143 | L = luaL_newstate(); |
| 144 | if (L == NULL) { |
| 145 | fail("luaL_newstate() error"); |
| 146 | return false; |
| 147 | } |
| 148 | |
| 149 | lua_pushlightuserdata(L, this); |
| 150 | lua_rawseti(L, LUA_REGISTRYINDEX, thisIndex); |
| 151 | |
| 152 | luaL_openlibs(L); |
| 153 | |
| 154 | // remove the "io" and "package" libraries |
| 155 | lua_pushnil(L); lua_setfield(L, LUA_GLOBALSINDEX, "io"); |
| 156 | lua_pushnil(L); lua_setfield(L, LUA_GLOBALSINDEX, "package"); |
| 157 | |
| 158 | // limit { os } table members |
| 159 | std::vector<std::string> osFuncs; |
| 160 | osFuncs.push_back("clock"); |
| 161 | osFuncs.push_back("date"); |
| 162 | osFuncs.push_back("time"); |
| 163 | osFuncs.push_back("difftime"); |
| 164 | limitMembers(L, "os", osFuncs); |
| 165 | |
| 166 | // limit { debug } table members |
| 167 | std::vector<std::string> debugFuncs; |
| 168 | debugFuncs.push_back("traceback"); |
| 169 | limitMembers(L, "debug", debugFuncs); |
| 170 | |
| 171 | // remove dofile() and loadfile() |
| 172 | lua_pushnil(L); lua_setglobal(L, "dofile"); |
| 173 | lua_pushnil(L); lua_setglobal(L, "loadfile"); |
| 174 | |
| 175 | if (!pushAnsiCodes()) { |
| 176 | fail("pushAnsiCodes() error"); |
| 177 | return false; |
| 178 | } |
| 179 | if (!pushConstants()) { |
| 180 | fail("pushConstants() error"); |
| 181 | return false; |
| 182 | } |
| 183 | if (!pushCallOuts()) { |
| 184 | fail("pushCallOuts() error"); |
| 185 | return false; |
| 186 | } |
| 187 | |
| 188 | // LuaDouble |
| 189 | lua_pushvalue(L, LUA_GLOBALSINDEX); |
| 190 | LuaDouble::PushEntries(L); |
| 191 | lua_pop(L, 1); |
| 192 | |
| 193 | const char* chunkName = codeFileName.c_str(); |
| 194 | if (luaL_loadbuffer(L, code.c_str(), code.size(), chunkName) != 0) { |
| 195 | std::string msg = "error: "; |
| 196 | msg += lua_tostring(L, -1); |
| 197 | fail(msg); |
nothing calls this directly
no test coverage detected