5 #include "BAREErrors.hpp"
10 void LuaScriptEngine::addValueToRegistry(lua_State* L, T* value, std::string key) {
12 lua_pushstring(L, key.c_str());
13 // Push the data (as a void*)
14 lua_pushlightuserdata(L, static_cast<void*>(value));
15 // Combine name and key in the registry.
16 lua_settable(L, LUA_REGISTRYINDEX);
20 T* LuaScriptEngine::getValueFromRegistry(lua_State* L, std::string key) {
21 // Put the key on the stack
22 lua_pushstring(L, key.c_str());
23 // Get the element at key in tge registry table
24 lua_gettable(L, LUA_REGISTRYINDEX);
25 // Turn the element into a void*
26 void* ret = lua_touserdata(L, -1);
28 // convert to whatever type
29 return static_cast<T*>(ret);