Skip to content

Commit

Permalink
Add documentation for runtime persistent cache
Browse files Browse the repository at this point in the history
Rename AsLua to AsTable
  • Loading branch information
Foereaper committed Jan 25, 2024
1 parent a8bca14 commit dc9e571
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion LuaValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
21 changes: 21 additions & 0 deletions TrinityCore/MapMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <pre>
* -- 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()
* </pre>
*/
int Data(Eluna* E, Map* map)
{
return LuaVal::PushLuaVal(E->L, map->lua_data);
Expand Down
21 changes: 21 additions & 0 deletions TrinityCore/WorldObjectMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <pre>
* -- 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()
* </pre>
*/
int Data(Eluna* E, WorldObject* obj)
{
return LuaVal::PushLuaVal(E->L, obj->lua_data);
Expand Down

0 comments on commit dc9e571

Please sign in to comment.