Load resources of a factory prototype. * * Resources are referenced by the factory component until the existing (parent) collection is destroyed or factory.unload is called. * * Calling this function when the factory is not marked as dynamic loading does nothing. * * @name factory.load * @param [url] [type:string|hash|url] the factory component to load * @pa
| 158 | * ``` |
| 159 | */ |
| 160 | static int FactoryComp_Load(lua_State* L) |
| 161 | { |
| 162 | int top = lua_gettop(L); |
| 163 | |
| 164 | if (top < 2 || !lua_isfunction(L, 2)) |
| 165 | { |
| 166 | return luaL_error(L, "Argument #2 is expected to be completion function."); |
| 167 | } |
| 168 | |
| 169 | dmMessage::URL receiver; |
| 170 | HFactoryWorld world; |
| 171 | HFactoryComponent component; |
| 172 | dmScript::GetComponentFromLua(L, 1, FACTORY_EXT, (dmGameObject::HComponentWorld*)&world, (dmGameObject::HComponent*)&component, &receiver); |
| 173 | |
| 174 | if (dmGameSystem::CompFactoryIsLoading(world, component)) { |
| 175 | dmLogError("Trying to load factory prototype resource when already loading."); |
| 176 | return luaL_error(L, "Error loading factory resources"); |
| 177 | } |
| 178 | |
| 179 | lua_pushvalue(L, 2); |
| 180 | int callback_ref = dmScript::Ref(L, LUA_REGISTRYINDEX); |
| 181 | dmScript::GetInstance(L); |
| 182 | int self_ref = dmScript::Ref(L, LUA_REGISTRYINDEX); |
| 183 | dmScript::PushURL(L, receiver); |
| 184 | int url_ref = dmScript::Ref(L, LUA_REGISTRYINDEX); |
| 185 | |
| 186 | bool success = dmGameSystem::CompFactoryLoad(world, component, callback_ref, self_ref, url_ref); |
| 187 | if (!success) |
| 188 | { |
| 189 | dmScript::Unref(L, LUA_REGISTRYINDEX, callback_ref); |
| 190 | dmScript::Unref(L, LUA_REGISTRYINDEX, self_ref); |
| 191 | dmScript::Unref(L, LUA_REGISTRYINDEX, url_ref); |
| 192 | return luaL_error(L, "Error loading factory resources"); |
| 193 | } |
| 194 | |
| 195 | assert(top == lua_gettop(L)); |
| 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | |
| 200 | /*# make a factory create a new game object |
nothing calls this directly
no test coverage detected