| 1073 | } |
| 1074 | |
| 1075 | int 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 | |
| 1104 | struct GluaStorageValue; |
| 1105 | struct GluaStorageValue lua_type_to_storage_value_type(lua_State *L, int index, size_t len); |
no test coverage detected