Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
WoW
Talk
English
Views
Read
Edit
History
More
Search
Navigation
Home
Random page
Help using wiki
Editions
for WoW
for WildStar
for Solar2D
Documentation
for WoW
for WildStar
Reference
WoW
⦁ FrameXML
⦁ AddOns
⦁ API
⦁ WoW Lua
WildStar
⦁ AddOns
⦁ API
⦁ WildStar Lua
Engine
Tools
What links here
Related changes
Special pages
Page information
Site
Recent Changes
Editing
WoW:USERAPI setArgs
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{userfunc}} <!-- Leave this line in! --> The setArgs() and getArgs() remember and retreive arguments for callback functions in a more memory efficient way. setArgs(myTable, "name", arg1, arg2, arg3,...) arg1,arg2,arg3,... = getArgs(myTable, "name"[, extra, arguments, ...]) == setArgs Parameters == === Arguments === :(myTable, "name", list,of,arguments,...) :;myTable : Table - where to store the arguments :;"name" : String - prefix to give the arguments, if you are storing arguments for multiple callbacks, otherwise "" :;... : List of arguments to be stored === Returns === :''nothing'' == getArgs Parameters == === Arguments === :(myTable, "name"[, ...]) :;myTable : Table - where to retreive the arguments from :;"name" : String - prefix used in setArgs :;... : (optional) - extra arguments to use after the stored ones === Returns === :All arguments stored by setArgs(), optionally followed by the extra arguments supplied to getArgs() == Example 1 == Just demonstrating how setArgs and getArgs actually work function out(...) for i=1,select("#", ...) do print(i.."="..tostring(select(i,...))) end end tbl = {} setArgs(tbl, "myArgList", "a", nil, "3") out( getArgs(tbl, "myArgList", "extra", nil, "cheese") ) ====Result==== 1=a 2=nil 3=3 4=extra 5=nil 6=cheese == Example 2 == Demonstrating how callbacks could be implemented in a "library" / addon that wants to be able to accept callback registrations from other sources === "Library" === local mytable = {} local function myUpdateHandler(this, delay) if mytable.callback then mytable.callback( getArgs(mytable, "arg", delay) ) end end function RegisterOnUpdateCallback(func, ...) mytable.callback = func setArgs(mytable, "arg", ...) end (There obviously needs to be a [[frame]] created that calls myUpdateHandler via [[OnUpdate]] also, but that's out of scope for the example) === "User" === function MyMod:OnUpdate(delay) print("OnUpdate fired after " delay " seconds"); end function MyMod:Initialize() SetOnUpdateCallback(MyMod.OnUpdate, self) end == Code == local getArgs do local numargs local function _get(t, str, i, ...) if i<=numargs then return t[format("%s%d", str, i)], _get(t, str, i+1, ...) end return ... end function getArgs(t, str, ...) numargs = t[str.."#" or 0] return _get(t,str,1, ...) end end local function setArgs(t, str, ...) local n = select("#", ...) for i=1,n do t[format("%s%d",str,i)]=select(i,...) end for i=n+1, (t[str.."#"] or 0) do t[format("%s%d",str,i)]=nil end t[str.."#"] = n end
Summary:
Please note that all contributions to AddOn Studio are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
AddOn Studio Wiki:Copyrights
for details).
Submissions must be written by you, or copied from a public domain or similar free resource (see
AddOn Studio Wiki:Copyrights
for details).
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Apinav
(
edit
)
Template:Editlink
(
edit
)
Template:Notebox
(
edit
)
Template:Userfunc
(
edit
)