| 3420 | } |
| 3421 | |
| 3422 | RenderScriptResult RunScript(HRenderScriptInstance script_instance, RenderScriptFunction script_function, void* args) |
| 3423 | { |
| 3424 | DM_PROFILE("RenderScript"); |
| 3425 | |
| 3426 | RenderScriptResult result = RENDER_SCRIPT_RESULT_OK; |
| 3427 | HRenderScript script = script_instance->m_RenderScript; |
| 3428 | if (script->m_FunctionReferences[script_function] != LUA_NOREF) |
| 3429 | { |
| 3430 | lua_State* L = script_instance->m_RenderContext->m_RenderScriptContext.m_LuaState; |
| 3431 | int top = lua_gettop(L); |
| 3432 | (void) top; |
| 3433 | |
| 3434 | lua_rawgeti(L, LUA_REGISTRYINDEX, script_instance->m_InstanceReference); |
| 3435 | dmScript::SetInstance(L); |
| 3436 | |
| 3437 | lua_rawgeti(L, LUA_REGISTRYINDEX, script->m_FunctionReferences[script_function]); |
| 3438 | lua_rawgeti(L, LUA_REGISTRYINDEX, script_instance->m_InstanceReference); |
| 3439 | |
| 3440 | int arg_count = 1; |
| 3441 | |
| 3442 | const char* message_name = 0; |
| 3443 | if (script_function == RENDER_SCRIPT_FUNCTION_ONMESSAGE) |
| 3444 | { |
| 3445 | arg_count = 4; |
| 3446 | |
| 3447 | dmMessage::Message* message = (dmMessage::Message*)args; |
| 3448 | dmScript::PushHash(L, message->m_Id); |
| 3449 | if (message->m_Descriptor != 0) |
| 3450 | { |
| 3451 | dmDDF::Descriptor* descriptor = (dmDDF::Descriptor*)message->m_Descriptor; |
| 3452 | // TODO: setjmp/longjmp here... how to handle?!!! We are not running "from lua" here |
| 3453 | // lua_cpcall? |
| 3454 | message_name = descriptor->m_Name; |
| 3455 | dmScript::PushDDF(L, descriptor, (const char*)message->m_Data, true); |
| 3456 | } |
| 3457 | else |
| 3458 | { |
| 3459 | if (ProfileIsInitialized()) |
| 3460 | { |
| 3461 | // Try to find the message name via id and reverse hash |
| 3462 | message_name = (const char*)dmHashReverse64(message->m_Id, 0); |
| 3463 | } |
| 3464 | if (message->m_DataSize > 0) |
| 3465 | { |
| 3466 | dmScript::PushTable(L, (const char*)message->m_Data, message->m_DataSize); |
| 3467 | } |
| 3468 | else |
| 3469 | { |
| 3470 | lua_newtable(L); |
| 3471 | } |
| 3472 | } |
| 3473 | dmScript::PushURL(L, message->m_Sender); |
| 3474 | } |
| 3475 | else if (script_function == RENDER_SCRIPT_FUNCTION_UPDATE) |
| 3476 | { |
| 3477 | float* dt = (float*)args; |
| 3478 | lua_pushnumber(L, (lua_Number) *dt); |
| 3479 | arg_count += 1; |
no test coverage detected