diff --git a/LuaValue.cpp b/LuaValue.cpp index 56b6c24020..a0be40eae1 100644 --- a/LuaValue.cpp +++ b/LuaValue.cpp @@ -73,7 +73,7 @@ void LuaVal::Register(lua_State* L) { lua_pushcfunction(L, &LuaVal::lua_AsLuaVal); lua_setfield(L, -2, "New"); lua_pushcfunction(L, &LuaVal::lua_asLua); - lua_setfield(L, -2, "AsLua"); + lua_setfield(L, -2, "AsTable"); lua_setglobal(L, "LuaVal"); } diff --git a/TrinityCore/MapMethods.h b/TrinityCore/MapMethods.h index 9bd3ffc72d..1fb45cffc2 100644 --- a/TrinityCore/MapMethods.h +++ b/TrinityCore/MapMethods.h @@ -337,6 +337,27 @@ namespace LuaMap return 1; } + /** + * Returns a runtime-persistent cache tied to the [Map]. + * This data will remain for as long as the [Map] exists, or until a server restart. + * + * A reload of the Lua state will NOT clear this cache. + * + * This cache can be added to and read from with the following sub-methods. + *
+     * -- Sets the key-value pair in the cache
+     * Map:Data():Set("key", val)
+     *
+     * -- Returns the value from the cache using the key
+     * local val = Map:Data():Get("key")
+     *
+     * -- Removes the key-value pair from the cache
+     * Map:Data():Set("key", nil)
+     *
+     * -- Returns all the key-value pairs as a Lua table indexed by the keys
+     * local table = Map:Data():AsTable()
+     * 
+ */ int Data(Eluna* E, Map* map) { return LuaVal::PushLuaVal(E->L, map->lua_data); diff --git a/TrinityCore/WorldObjectMethods.h b/TrinityCore/WorldObjectMethods.h index 39c5c95f29..a60d6f0bb2 100644 --- a/TrinityCore/WorldObjectMethods.h +++ b/TrinityCore/WorldObjectMethods.h @@ -1130,6 +1130,27 @@ namespace LuaWorldObject return 0; } + /** + * Returns a runtime-persistent cache tied to the [WorldObject]. + * This data will remain for as long as the [WorldObject] exists, or until a server restart. + * + * A reload of the Lua state will NOT clear this cache. + * + * This cache can be added to and read from with the following sub-methods. + *
+     * -- Sets the key-value pair in the cache
+     * WorldObject:Data():Set("key", val)
+     *
+     * -- Returns the value from the cache using the key
+     * local val = WorldObject:Data():Get("key")
+     *
+     * -- Removes the key-value pair from the cache
+     * WorldObject:Data():Set("key", nil)
+     *
+     * -- Returns all the key-value pairs as a Lua table indexed by the keys
+     * local table = WorldObject:Data():AsTable()
+     * 
+ */ int Data(Eluna* E, WorldObject* obj) { return LuaVal::PushLuaVal(E->L, obj->lua_data);