macro.lua (508B)
1 local Macros = { } 2 3 local function doMacro( key ) 4 local macro = Macros[ key ] 5 6 if macro then 7 macro() 8 end 9 end 10 11 function mud.macro( key, callback, disabled ) 12 enforce( key, "key", "string" ) 13 enforce( callback, "callback", "function", "string" ) 14 15 if type( callback ) == "string" then 16 local command = callback 17 18 callback = function() 19 mud.input( command ) 20 end 21 end 22 23 assert( not Macros[ key ], "macro `%s' already registered" % key ) 24 25 26 Macros[ key ] = callback 27 end 28 29 return { 30 doMacro = doMacro, 31 }