MCPcopy Create free account
hub / github.com/defold/defold / ReloadModule

Function ReloadModule

engine/script/src/script_module.cpp:146–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

144 }
145
146 Result ReloadModule(HContext context, dmLuaDDF::LuaSource *source, dmhash_t path_hash)
147 {
148 lua_State* L = GetLuaState(context);
149 int top = lua_gettop(L);
150 (void) top;
151
152 Module** module_handle = context->m_PathToModule.Get(path_hash);
153 if (module_handle == 0)
154 {
155 return RESULT_MODULE_NOT_LOADED;
156 }
157 Module* module = *module_handle;
158
159 const char *buf;
160 uint32_t size;
161 GetLuaSource(source, &buf, &size);
162
163 module->m_Script = (char*) realloc(module->m_Script, size);
164 module->m_ScriptSize = size;
165 memcpy(module->m_Script, buf, size);
166
167 if (LuaLoadModule(L, buf, size, module->m_Name))
168 {
169 lua_pushstring(L, module->m_Name);
170 int ret = dmScript::PCall(L, 1, LUA_MULTRET);
171 if (ret != 0)
172 {
173 assert(top == lua_gettop(L));
174 return RESULT_LUA_ERROR;
175 }
176 // As we only run the module for the sake of reloading (updating data), it is safe to remove any module return values here
177 lua_pop(L, lua_gettop(L) - top);
178 }
179 else
180 {
181 assert(top == lua_gettop(L));
182 return RESULT_LUA_ERROR;
183 }
184 assert(top == lua_gettop(L));
185 return RESULT_OK;
186 }
187
188 static void FreeModuleCallback(void* context, const uint64_t* key, Module* value)
189 {

Callers 2

ResLuaRecreateFunction · 0.85
TEST_FFunction · 0.85

Calls 9

lua_gettopFunction · 0.85
GetLuaSourceFunction · 0.85
reallocFunction · 0.85
LuaLoadModuleFunction · 0.85
lua_pushstringFunction · 0.85
PCallFunction · 0.85
GetLuaStateFunction · 0.70
assertFunction · 0.50
GetMethod · 0.45

Tested by 1

TEST_FFunction · 0.68