MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / luaL_require_module

Function luaL_require_module

src/Chain/libraries/glua/lauxlib.cpp:1075–1102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1073}
1074
1075int luaL_require_module(lua_State *L)
1076{
1077 if (lua_gettop(L) < 1)
1078 {
1079 global_glua_chain_api->throw_exception(L, THINKYOUNG_API_SIMPLE_ERROR, "require need 1 argument of contract name");
1080 return 0;
1081 }
1082 const char *name = luaL_checkstring(L, 1);
1083 lua_settop(L, 1); /* _LOADED table will be at index 2 */
1084 lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
1085 lua_getfield(L, 2, name); /* _LOADED[name] */
1086 if (lua_toboolean(L, -1)) /* is it there? */
1087 return 1; /* package is already loaded */
1088 /* else must load package */
1089 lua_pop(L, 1); /* remove 'getfield' result */
1090 bool loaderfound = findloader(L, name);
1091 lua_pushstring(L, name); /* pass name as argument to module loader */
1092 lua_insert(L, -2); /* name is 1st argument (before search data) */
1093 lua_call(L, 2, 1); /* run loader to load module */
1094 if (!lua_isnil(L, -1)) /* non-nil return? */
1095 lua_setfield(L, 2, name); /* _LOADED[name] = returned value */
1096 if (lua_getfield(L, 2, name) == LUA_TNIL) { /* module set no value? */
1097 lua_pushboolean(L, 1); /* use true as result */
1098 lua_pushvalue(L, -1); /* extra copy to be returned */
1099 lua_setfield(L, 2, name); /* _LOADED[name] = true */
1100 }
1101 return 1;
1102}
1103
1104struct GluaStorageValue;
1105struct GluaStorageValue lua_type_to_storage_value_type(lua_State *L, int index, size_t len);

Callers 1

ll_requireFunction · 0.85

Calls 10

lua_gettopFunction · 0.85
lua_settopFunction · 0.85
lua_getfieldFunction · 0.85
lua_tobooleanFunction · 0.85
lua_pushstringFunction · 0.85
lua_setfieldFunction · 0.85
lua_pushbooleanFunction · 0.85
lua_pushvalueFunction · 0.85
findloaderFunction · 0.70
throw_exceptionMethod · 0.45

Tested by

no test coverage detected