MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / getUserData

Method getUserData

source/core/StarLua.hpp:2169–2192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2167
2168template <typename T>
2169T* LuaEngine::getUserData(int handleIndex) {
2170 int typeRef = m_registeredUserDataTypes.value(typeid(T), LUA_NOREF);
2171 if (typeRef == LUA_NOREF)
2172 throw LuaException::format("Cannot convert userdata type of {}, not registered", typeid(T).name());
2173
2174 lua_checkstack(m_state, 3);
2175
2176 pushHandle(m_state, handleIndex);
2177 T* userdata = (T*)lua_touserdata(m_state, -1);
2178 if (lua_getmetatable(m_state, -1) == 0) {
2179 lua_pop(m_state, 1);
2180 throw LuaException("Cannot get userdata from lua type, no metatable found");
2181 }
2182
2183 lua_rawgeti(m_state, LUA_REGISTRYINDEX, typeRef);
2184 if (!lua_rawequal(m_state, -1, -2)) {
2185 lua_pop(m_state, 3);
2186 throw LuaException::format("Improper conversion from userdata to type {}", typeid(T).name());
2187 }
2188
2189 lua_pop(m_state, 3);
2190
2191 return userdata;
2192}
2193
2194inline void LuaEngine::destroyHandle(int handleIndex) {
2195 // We don't bother setting the entry in the handle stack to nil, we just wait

Callers

nothing calls this directly

Calls 8

lua_checkstackFunction · 0.85
lua_touserdataFunction · 0.85
lua_getmetatableFunction · 0.85
lua_rawgetiFunction · 0.85
lua_rawequalFunction · 0.85
formatFunction · 0.70
valueMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected