feat: add CreateFrame with RegisterEvent/SetScript for WoW addon pattern

Implement the core WoW frame system that nearly all addons use:

- CreateFrame(type, name, parent, template) — creates a frame table
  with metatable methods, optionally registered as a global by name
- frame:RegisterEvent(event) — register frame for event dispatch
- frame:UnregisterEvent(event) — unregister
- frame:SetScript(type, handler) — set OnEvent/OnUpdate/etc handlers
- frame:GetScript(type) — retrieve handlers
- frame:Show()/Hide()/IsShown()/IsVisible() — visibility state
- frame:GetName() — return frame name

Event dispatch now fires both global RegisterEvent handlers AND
frame OnEvent scripts, matching WoW's dual dispatch model.

Updated HelloWorld to use standard WoW addon pattern:
  local f = CreateFrame("Frame", "MyFrame")
  f:RegisterEvent("PLAYER_ENTERING_WORLD")
  f:SetScript("OnEvent", function(self, event, ...) end)
This commit is contained in:
Kelsi 2026-03-20 11:46:04 -07:00
parent c1820fd07d
commit c284a971c2
2 changed files with 233 additions and 20 deletions

View file

@ -1,24 +1,28 @@
-- HelloWorld addon — test the WoWee addon system
print("|cff00ff00[HelloWorld]|r Addon loaded! Lua 5.1 is working.")
-- HelloWorld addon — demonstrates the WoWee addon system
-- Register for game events
RegisterEvent("PLAYER_ENTERING_WORLD", function(event)
local name = UnitName("player")
local level = UnitLevel("player")
local health = UnitHealth("player")
local maxHealth = UnitHealthMax("player")
local _, _, classId = UnitClass("player")
local gold = math.floor(GetMoney() / 10000)
-- Create a frame and register for events (standard WoW addon pattern)
local f = CreateFrame("Frame", "HelloWorldFrame")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:RegisterEvent("CHAT_MSG_SAY")
print("|cff00ff00[HelloWorld]|r Welcome, " .. name .. "! (Level " .. level .. ")")
if maxHealth > 0 then
print("|cff00ff00[HelloWorld]|r Health: " .. health .. "/" .. maxHealth)
end
if gold > 0 then
print("|cff00ff00[HelloWorld]|r Gold: " .. gold .. "g")
f:SetScript("OnEvent", function(self, event, ...)
if event == "PLAYER_ENTERING_WORLD" then
local name = UnitName("player")
local level = UnitLevel("player")
print("|cff00ff00[HelloWorld]|r Welcome, " .. name .. "! (Level " .. level .. ")")
elseif event == "CHAT_MSG_SAY" then
local msg, sender = ...
if msg and sender then
print("|cff00ff00[HelloWorld]|r " .. sender .. " said: " .. msg)
end
end
end)
RegisterEvent("PLAYER_LEAVING_WORLD", function(event)
print("|cff00ff00[HelloWorld]|r Goodbye!")
end)
-- Register a custom slash command
SLASH_HELLOWORLD1 = "/hello"
SLASH_HELLOWORLD2 = "/hw"
SlashCmdList["HELLOWORLD"] = function(args)
print("|cff00ff00[HelloWorld]|r Hello! " .. (args ~= "" and args or "Type /hello <message>"))
end
print("|cff00ff00[HelloWorld]|r Addon loaded. Type /hello to test slash commands.")