Lua can't interpret Mushclient variables, like Mushclient itself can. But what you want can still be accomplished, although with some hoops to jump.
You can make your queue hold tables, instead of strings. Each table should have a boolean field, called "interp" for example. So that a plain string that should be sent directly to the MUD without any processing has field "interp" set false, while a table with a string that needs to have variables expanded or contains a script has "interp" set true.
Further, when retrieving a table from a queue, you check the "interp" field and if it is true then you add a temporary alias, set its Send property to the table's string, set it to send to scripting, set expand variables, and Execute that alias. It'll probably make more sense in code (I've also added an option to send to scripting):
queue = {}
table.insert(queue, "say Hello!")
table.insert(queue, {interp=true, text="tell @person Hello!"})
table.insert(queue, {interp=true, script=true, text="Send('tell @person Hello!')"})
function remove_alias(name)
EnableAlias(name, false)
DoAfterSpecial (1, "DeleteAlias ('" .. name .. "')", 12) -- delete it
end
function sendQueue()
local tosend = table.remove(queue)
-- if its a plain string then we don't need to do anything special
--
if type(tosend) == "string" then
Send(tosend)
return
-- if its a table then we need to execute it through an alias
--
elseif type(tosend) == "table" then
-- set the default flags for the alias
local flags = alias_flag.Enabled + alias_flag.Temporary
-- if the "interp" option is set then alias needs to expand variables
flags = tosend.interp and (flags + alias_flag.ExpandVariables) or flags
-- get a unique number to use for alias' match and name
local alias_id = GetUniqueID()
-- create the alias
AddAlias("queue_alias_" .. alias_id, alias_id, tosend.text, flags, "remove_alias")
-- if the "script" option is set then the alias must also send to scripting
--
if tosend.script then
SetAliasOption("queue_alias_" .. alias_id, "send_to", "12")
end
-- execute the alias
Execute(alias_id)
end
end
-- test it
--
sendQueue()
sendQueue()
sendQueue()
|