MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / createLua

Method createLua

src/bzflag/HubLua.cpp:140–222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

138//============================================================================//
139
140bool 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);

Callers

nothing calls this directly

Calls 15

setupCallInMapsFunction · 0.85
limitMembersFunction · 0.85
c_strMethod · 0.80
getJoinPortMethod · 0.80
luaL_newstateFunction · 0.50
lua_pushlightuserdataFunction · 0.50
lua_rawsetiFunction · 0.50
luaL_openlibsFunction · 0.50
lua_pushnilFunction · 0.50
lua_setfieldFunction · 0.50
lua_pushvalueFunction · 0.50
luaL_loadbufferFunction · 0.50

Tested by

no test coverage detected