MCPcopy Create free account
hub / github.com/crownengine/crown / add_module_metafunction

Method add_module_metafunction

src/lua/lua_environment.cpp:437–463  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

435}
436
437void LuaEnvironment::add_module_metafunction(const char *module, const char *name, const lua_CFunction func)
438{
439 // Create module if it does not exist
440 luaL_Reg entry[2];
441 entry[0].name = NULL;
442 entry[0].func = NULL;
443 luaL_register(L, module, entry);
444 lua_pop(L, 1);
445
446 luaL_newmetatable(L, module);
447 if (func) {
448 entry[0].name = name;
449 entry[0].func = func;
450 entry[1].name = NULL;
451 entry[1].func = NULL;
452 luaL_register(L, NULL, entry);
453 } else {
454 lua_pushstring(L, name);
455 lua_pushvalue(L, -2);
456 lua_settable(L, -3);
457 }
458
459 lua_getglobal(L, module);
460 lua_pushvalue(L, -2);
461 lua_setmetatable(L, -2);
462 lua_pop(L, 2);
463}
464
465void LuaEnvironment::set_module_number(const char *module, const char *name, f64 value)
466{

Callers 1

load_apiFunction · 0.80

Calls 6

luaL_registerFunction · 0.50
luaL_newmetatableFunction · 0.50
lua_pushstringFunction · 0.50
lua_pushvalueFunction · 0.50
lua_settableFunction · 0.50
lua_setmetatableFunction · 0.50

Tested by

no test coverage detected