MCPcopy Create free account
hub / github.com/defold/defold / GetUserData

Function GetUserData

engine/script/src/script.cpp:928–997  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

926 }
927
928 bool GetUserData(lua_State* L, uintptr_t* out_user_data, uint32_t user_type_hash) {
929 DM_LUA_STACK_CHECK(L, 0);
930
931 GetInstance(L);
932 // [-1] instance
933
934 if (lua_type(L, -1) != LUA_TUSERDATA)
935 {
936 lua_pop(L, 1);
937 return false;
938 }
939
940 if (!lua_getmetatable(L, -1))
941 {
942 lua_pop(L, 1);
943 return false;
944 }
945 // [-1] meta table
946 // [-2] instance
947
948 lua_pushinteger(L, SCRIPT_METATABLE_TYPE_HASH_KEY);
949 // [-1] SCRIPT_METATABLE_TYPE_HASH_KEY
950 // [-2] meta table
951 // [-3] instance
952
953 lua_rawget(L, -2);
954 // [-1] type hash
955 // [-2] meta table
956 // [-3] instance
957
958 if (lua_tointeger(L, -1) != user_type_hash)
959 {
960 lua_pop(L, 3);
961 return false;
962 }
963
964 lua_pop(L, 1);
965 // [-1] meta table
966 // [-2] instance
967
968 lua_pushlstring(L, META_TABLE_GET_USER_DATA, sizeof(META_TABLE_GET_USER_DATA) - 1);
969 // [-1] META_TABLE_GET_USER_DATA
970 // [-2] meta table
971 // [-3] instance
972
973 lua_rawget(L, -2);
974 // [-1] get_user_data method
975 // [-2] meta table
976 // [-3] instance
977
978 if (lua_isnil(L, -1)) {
979 lua_pop(L, 3);
980 return false;
981 }
982
983 lua_pushvalue(L, -3);
984 // [-1] instance
985 // [-2] get_user_data

Callers 4

GetInstanceFromLuaFunction · 0.85
TEST_FFunction · 0.85
TEST_FFunction · 0.85
QueryMethod · 0.85

Calls 10

lua_typeFunction · 0.85
lua_getmetatableFunction · 0.85
lua_pushintegerFunction · 0.85
lua_rawgetFunction · 0.85
lua_tointegerFunction · 0.85
lua_pushlstringFunction · 0.85
lua_pushvalueFunction · 0.85
lua_callFunction · 0.85
lua_touserdataFunction · 0.85
GetInstanceFunction · 0.70

Tested by 2

TEST_FFunction · 0.68
TEST_FFunction · 0.68