| 1787 | } |
| 1788 | |
| 1789 | static bool IsCallbackInstanceValid(LuaCallbackInfo* cbk) |
| 1790 | { |
| 1791 | if (cbk->m_UniqueScriptId == INVALID_SCRIPT_ID) |
| 1792 | { |
| 1793 | return false; |
| 1794 | } |
| 1795 | lua_State* L = cbk->m_L; |
| 1796 | DM_LUA_STACK_CHECK(L, 0); |
| 1797 | |
| 1798 | GetInstance(L); |
| 1799 | // [-1] old instance |
| 1800 | lua_rawgeti(L, LUA_REGISTRYINDEX, cbk->m_ContextTableRef); |
| 1801 | // [-2] old instance |
| 1802 | // [-1] context table |
| 1803 | if (lua_type(L, -1) != LUA_TTABLE) |
| 1804 | { |
| 1805 | lua_pop(L, 2); |
| 1806 | cbk->m_UniqueScriptId = INVALID_SCRIPT_ID; |
| 1807 | return false; |
| 1808 | } |
| 1809 | |
| 1810 | const int context_table_stack_index = lua_gettop(L); |
| 1811 | lua_rawgeti(L, context_table_stack_index, cbk->m_Self); |
| 1812 | // [-3] old instance |
| 1813 | // [-2] context table |
| 1814 | // [-1] instance |
| 1815 | if (lua_isnil(L, -1)) |
| 1816 | { |
| 1817 | lua_pop(L, 3); |
| 1818 | cbk->m_UniqueScriptId = INVALID_SCRIPT_ID; |
| 1819 | return false; |
| 1820 | } |
| 1821 | |
| 1822 | lua_pushvalue(L, -1); |
| 1823 | // [-4] old instance |
| 1824 | // [-3] context table |
| 1825 | // [-2] instance |
| 1826 | // [-1] instance |
| 1827 | SetInstance(L); |
| 1828 | // [-3] old instance |
| 1829 | // [-2] context table |
| 1830 | // [-1] instance |
| 1831 | uint32_t unique_script_id = INVALID_SCRIPT_ID; |
| 1832 | if (GetMetaFunction(L, -1, META_GET_UNIQUE_SCRIPT_ID, sizeof(META_GET_UNIQUE_SCRIPT_ID) - 1)) |
| 1833 | { |
| 1834 | // [-4] old instance |
| 1835 | // [-3] context table |
| 1836 | // [-2] instance |
| 1837 | // [-1] META_GET_UNIQUE_SCRIPT_ID() |
| 1838 | lua_pushvalue(L, -2); |
| 1839 | // [-5] old instance |
| 1840 | // [-4] context table |
| 1841 | // [-3] instance |
| 1842 | // [-2] META_GET_UNIQUE_SCRIPT_ID() |
| 1843 | // [-1] instance |
| 1844 | lua_call(L, 1, 1); |
| 1845 | // [-4] old instance |
| 1846 | // [-3] context table |
no test coverage detected