Recently I had occasion to convert a VBscript plugin to Lua. An interesting problem that occurred doing that was that VBscript is not case-sensitive when using inbuilt MUSHclient functions. For example, you can use:
However the correct capitalization is actually:
If you have to convert a script like that, or simply want to make your scripts more "correct" you can use the new Global Replace feature of the notepad to quickly do it in one step.
To assist in this process I added a new Lua utility function utils.functionlist, which returns a table of all internal function names. This appears in version 3.73 of MUSHclient. However if you are using a slightly older version you could simply use a table of all known functions.
Here is how you do it.
Use the Notepad's Search -> Global Replace dialog, entering:
Taking as an example some code that Shadowfyr posted recently:
The other thing you could do is replace the "world.function" calls by omitting "world.". You could do that like this:
Now the results look like this:
world.setvariable ("a", 42)
However the correct capitalization is actually:
world.SetVariable ("a", 42)
If you have to convert a script like that, or simply want to make your scripts more "correct" you can use the new Global Replace feature of the notepad to quickly do it in one step.
To assist in this process I added a new Lua utility function utils.functionlist, which returns a table of all internal function names. This appears in version 3.73 of MUSHclient. However if you are using a slightly older version you could simply use a table of all known functions.
Here is how you do it.
Use the Notepad's Search -> Global Replace dialog, entering:
Find Pattern: [%a%d]+
Replacement: f
Script:
t1 = utils.functionlist ()
t2 = {}
-- keys are lower-case functions, values are original functions
table.foreach (t1, function (k, v) t2 [string.lower (v)] = v end )
function f (str)
return t2 [string.lower (str)] or str
end -- function f
Taking as an example some code that Shadowfyr posted recently:
Before replacement:
sub ResetTmr (name, output, wildcards)
dim Icnm ' Names.
dim Tms ' Current times.
dim Ada
Ada = split(world.getvariable("Ada"),",")
Icnm = split(world.getvariable("Icnm"),",")
Tms = split(world.getvariable("Tms"),",")
dim count,test
test = 0
for count = 0 to ubound(Icnm)
if Icnm(count) = name then
Tms(count) = 0
if ada(count) > 0 then
test = 1
end if
end if
next
world.setvariable "Tms", join(Tms,",")
if test then
world.enabletrigger "CatchStat", 1
world.send "stats"
end if
end sub
After replacement:
sub ResetTmr (name, output, wildcards)
dim Icnm ' Names.
dim Tms ' Current times.
dim Ada
Ada = split(world.GetVariable("Ada"),",")
Icnm = split(world.GetVariable("Icnm"),",")
Tms = split(world.GetVariable("Tms"),",")
dim count,test
test = 0
for count = 0 to ubound(Icnm)
if Icnm(count) = name then
Tms(count) = 0
if ada(count) > 0 then
test = 1
end if
end if
next
world.SetVariable "Tms", join(Tms,",")
if test then
world.EnableTrigger "CatchStat", 1
world.Send "stats"
end if
end sub
The other thing you could do is replace the "world.function" calls by omitting "world.". You could do that like this:
Find Pattern: [Ww]orld.([%a%d]+)
Replacement: %1
Now the results look like this:
sub ResetTmr (name, output, wildcards)
dim Icnm ' Names.
dim Tms ' Current times.
dim Ada
Ada = split(GetVariable("Ada"),",")
Icnm = split(GetVariable("Icnm"),",")
Tms = split(GetVariable("Tms"),",")
dim count,test
test = 0
for count = 0 to ubound(Icnm)
if Icnm(count) = name then
Tms(count) = 0
if ada(count) > 0 then
test = 1
end if
end if
next
SetVariable "Tms", join(Tms,",")
if test then
EnableTrigger "CatchStat", 1
Send "stats"
end if
end sub