mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-22 23:30:14 +00:00
Foundation for WoW-compatible addon support: - Vendor Lua 5.1.5 source as a static library (extern/lua-5.1.5) - TocParser: parses .toc files (## directives + file lists) - LuaEngine: Lua 5.1 VM with sandboxed stdlib (no io/os/debug), WoW-compatible print() that outputs to chat, GetTime() stub - AddonManager: scans Data/interface/AddOns/ for .toc files, loads .lua files on world entry, skips LoadOnDemand addons - /run <code> slash command for inline Lua execution - HelloWorld test addon that prints to chat on load Integration: AddonManager initialized after asset manager, addons loaded once on first world entry, reset on logout. XML frame parsing is deferred to a future step.
40 lines
605 B
Lua
40 lines
605 B
Lua
-- fibonacci function with cache
|
|
|
|
-- very inefficient fibonacci function
|
|
function fib(n)
|
|
N=N+1
|
|
if n<2 then
|
|
return n
|
|
else
|
|
return fib(n-1)+fib(n-2)
|
|
end
|
|
end
|
|
|
|
-- a general-purpose value cache
|
|
function cache(f)
|
|
local c={}
|
|
return function (x)
|
|
local y=c[x]
|
|
if not y then
|
|
y=f(x)
|
|
c[x]=y
|
|
end
|
|
return y
|
|
end
|
|
end
|
|
|
|
-- run and time it
|
|
function test(s,f)
|
|
N=0
|
|
local c=os.clock()
|
|
local v=f(n)
|
|
local t=os.clock()-c
|
|
print(s,n,v,t,N)
|
|
end
|
|
|
|
n=arg[1] or 24 -- for other values, do lua fib.lua XX
|
|
n=tonumber(n)
|
|
print("","n","value","time","evals")
|
|
test("plain",fib)
|
|
fib=cache(fib)
|
|
test("cached",fib)
|