| 2024 | } |
| 2025 | |
| 2026 | bool InvokeCallback(LuaCallbackInfo* cbk, LuaCallbackUserFn fn, void* user_context) |
| 2027 | { |
| 2028 | lua_State* L = cbk->m_L; |
| 2029 | DM_LUA_STACK_CHECK(L, 0); |
| 2030 | |
| 2031 | if (!SetupCallback(cbk)) { |
| 2032 | return false; |
| 2033 | } |
| 2034 | // [-4] old instance |
| 2035 | // [-3] context table |
| 2036 | // [-2] callback |
| 2037 | // [-1] self |
| 2038 | |
| 2039 | int user_args_start = lua_gettop(L); |
| 2040 | |
| 2041 | if (fn) |
| 2042 | fn(L, user_context); |
| 2043 | |
| 2044 | int user_args_end = lua_gettop(L); |
| 2045 | |
| 2046 | int number_of_arguments = 1 + user_args_end - user_args_start; // instance + number of arguments that the user pushed |
| 2047 | |
| 2048 | int ret; |
| 2049 | { |
| 2050 | char buffer[128]; |
| 2051 | const char* profiler_string = GetProfilerString(L, -(number_of_arguments + 1), "?", "on_timer", 0, buffer, sizeof(buffer)); // TODO: Why "on_timer" ??? |
| 2052 | DM_PROFILE_DYN(profiler_string, 0); |
| 2053 | |
| 2054 | ret = PCall(L, number_of_arguments, 0); |
| 2055 | } |
| 2056 | |
| 2057 | // [-2] old instance |
| 2058 | // [-1] context table |
| 2059 | TeardownCallback(cbk); |
| 2060 | |
| 2061 | return ret != 0 ? false : true; |
| 2062 | } |
| 2063 | |
| 2064 | /** Information about a function, in which file and at what line it is defined |
| 2065 | * Use with GetLuaFunctionRefInfo |