mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-26 00:40:15 +00:00
feat: add Mixin, CreateFromMixins, and MergeTable utilities
Implement the WoW Mixin pattern used by modern addons: - Mixin(obj, ...) — copies fields from mixin tables into obj - CreateFromMixins(...) — creates a new table from mixin templates - CreateAndInitFromMixin(mixin, ...) — creates and calls Init() - MergeTable(dest, src) — shallow-merge src into dest These enable OOP-style addon architecture used by LibSharedMedia, WeakAuras, and many Ace3-based addons for class/object creation.
This commit is contained in:
parent
7b88b0c6ec
commit
42f2873c0d
1 changed files with 20 additions and 0 deletions
|
|
@ -5955,6 +5955,26 @@ void LuaEngine::registerCoreAPI() {
|
|||
"function tDeleteItem(tbl, item)\n"
|
||||
" for i = #tbl, 1, -1 do if tbl[i] == item then table.remove(tbl, i) end end\n"
|
||||
"end\n"
|
||||
// Mixin pattern — used by modern addons for OOP-style object creation
|
||||
"function Mixin(obj, ...)\n"
|
||||
" for i = 1, select('#', ...) do\n"
|
||||
" local mixin = select(i, ...)\n"
|
||||
" for k, v in pairs(mixin) do obj[k] = v end\n"
|
||||
" end\n"
|
||||
" return obj\n"
|
||||
"end\n"
|
||||
"function CreateFromMixins(...)\n"
|
||||
" return Mixin({}, ...)\n"
|
||||
"end\n"
|
||||
"function CreateAndInitFromMixin(mixin, ...)\n"
|
||||
" local obj = CreateFromMixins(mixin)\n"
|
||||
" if obj.Init then obj:Init(...) end\n"
|
||||
" return obj\n"
|
||||
"end\n"
|
||||
"function MergeTable(dest, src)\n"
|
||||
" for k, v in pairs(src) do dest[k] = v end\n"
|
||||
" return dest\n"
|
||||
"end\n"
|
||||
// String utilities (WoW globals that alias Lua string functions)
|
||||
"strupper = string.upper\n"
|
||||
"strlower = string.lower\n"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue