| 3180 | } |
| 3181 | |
| 3182 | static bool LoadRenderScript(lua_State* L, dmLuaDDF::LuaSource *source, RenderScript* script) |
| 3183 | { |
| 3184 | for (uint32_t i = 0; i < MAX_RENDER_SCRIPT_FUNCTION_COUNT; ++i) |
| 3185 | script->m_FunctionReferences[i] = LUA_NOREF; |
| 3186 | |
| 3187 | bool result = false; |
| 3188 | int top = lua_gettop(L); |
| 3189 | (void) top; |
| 3190 | |
| 3191 | int ret = dmScript::LuaLoad(L, source); |
| 3192 | if (ret == 0) |
| 3193 | { |
| 3194 | lua_rawgeti(L, LUA_REGISTRYINDEX, script->m_InstanceReference); |
| 3195 | dmScript::SetInstance(L); |
| 3196 | |
| 3197 | ret = dmScript::PCall(L, 0, 0); |
| 3198 | if (ret == 0) |
| 3199 | { |
| 3200 | for (uint32_t i = 0; i < MAX_RENDER_SCRIPT_FUNCTION_COUNT; ++i) |
| 3201 | { |
| 3202 | lua_getglobal(L, RENDER_SCRIPT_FUNCTION_NAMES[i]); |
| 3203 | if (lua_isnil(L, -1) == 0) |
| 3204 | { |
| 3205 | if (lua_type(L, -1) == LUA_TFUNCTION) |
| 3206 | { |
| 3207 | script->m_FunctionReferences[i] = dmScript::Ref(L, LUA_REGISTRYINDEX); |
| 3208 | } |
| 3209 | else |
| 3210 | { |
| 3211 | dmLogError("The global name '%s' in '%s' must be a function.", RENDER_SCRIPT_FUNCTION_NAMES[i], source->m_Filename); |
| 3212 | lua_pop(L, 1); |
| 3213 | goto bail; |
| 3214 | } |
| 3215 | } |
| 3216 | else |
| 3217 | { |
| 3218 | script->m_FunctionReferences[i] = LUA_NOREF; |
| 3219 | lua_pop(L, 1); |
| 3220 | } |
| 3221 | } |
| 3222 | result = true; |
| 3223 | script->m_SourceFileName = strdup(source->m_Filename); |
| 3224 | } |
| 3225 | lua_pushnil(L); |
| 3226 | dmScript::SetInstance(L); |
| 3227 | } |
| 3228 | else |
| 3229 | { |
| 3230 | dmLogError("Error running script: %s", lua_tostring(L,-1)); |
| 3231 | lua_pop(L, 1); |
| 3232 | } |
| 3233 | bail: |
| 3234 | for (uint32_t i = 0; i < MAX_RENDER_SCRIPT_FUNCTION_COUNT; ++i) |
| 3235 | { |
| 3236 | lua_pushnil(L); |
| 3237 | lua_setglobal(L, RENDER_SCRIPT_FUNCTION_NAMES[i]); |
| 3238 | } |
| 3239 | assert(top == lua_gettop(L)); |
no test coverage detected