Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Tips and tricks ➜ How to fix capitalization of function names in scripts

How to fix capitalization of function names in scripts

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Thu 29 Dec 2005 07:26 PM (UTC)

Amended on Thu 29 Dec 2005 11:09 PM (UTC) by Nick Gammon

Message
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:


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

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #1 on Thu 29 Dec 2005 07:34 PM (UTC)

Amended on Thu 29 Dec 2005 07:44 PM (UTC) by Nick Gammon

Message
If you want to try this out today, without waiting for the new version, here is a replacement for the first line of the script, that has all current function names in it:


t1 = {
  "Accelerator",
  "AcceleratorList",
  "Activate",
  "ActivateClient",
  "ActivateNotepad",
  "AddAlias",
  "AddMapperComment",
  "AddTimer",
  "AddToMapper",
  "AddTrigger",
  "AddTriggerEx",
  "AdjustColour",
  "ANSI",
  "AnsiNote",
  "AppendToNotepad",
  "ArrayClear",
  "ArrayCount",
  "ArrayCreate",
  "ArrayDelete",
  "ArrayDeleteKey",
  "ArrayExists",
  "ArrayExport",
  "ArrayExportKeys",
  "ArrayGet",
  "ArrayGetFirstKey",
  "ArrayGetLastKey",
  "ArrayImport",
  "ArrayKeyExists",
  "ArrayListAll",
  "ArrayListKeys",
  "ArrayListValues",
  "ArraySet",
  "ArraySize",
  "Base64Decode",
  "Base64Encode",
  "BoldColour",
  "BroadcastPlugin",
  "CallPlugin",
  "ChatAcceptCalls",
  "ChatCall",
  "ChatCallzChat",
  "ChatDisconnect",
  "ChatDisconnectAll",
  "ChatEverybody",
  "ChatGetID",
  "ChatGroup",
  "ChatID",
  "ChatMessage",
  "ChatNameChange",
  "ChatNote",
  "ChatPasteEverybody",
  "ChatPasteText",
  "ChatPeekConnections",
  "ChatPersonal",
  "ChatPing",
  "ChatRequestConnections",
  "ChatSendFile",
  "ChatStopAcceptingCalls",
  "ChatStopFileTransfer",
  "CloseLog",
  "CloseNotepad",
  "ColourNameToRGB",
  "ColourNote",
  "ColourTell",
  "Connect",
  "CreateGUID",
  "CustomColourBackground",
  "CustomColourText",
  "Debug",
  "DeleteAlias",
  "DeleteAliasGroup",
  "DeleteAllMapItems",
  "DeleteCommandHistory",
  "DeleteGroup",
  "DeleteLastMapItem",
  "DeleteOutput",
  "DeleteTemporaryAliases",
  "DeleteTemporaryTimers",
  "DeleteTemporaryTriggers",
  "DeleteTimer",
  "DeleteTimerGroup",
  "DeleteTrigger",
  "DeleteTriggerGroup",
  "DeleteVariable",
  "DiscardQueue",
  "Disconnect",
  "DoAfter",
  "DoAfterNote",
  "DoAfterSpecial",
  "DoAfterSpeedWalk",
  "DoCommand",
  "EchoInput",
  "EnableAlias",
  "EnableAliasGroup",
  "EnableGroup",
  "EnableMapping",
  "EnablePlugin",
  "EnableTimer",
  "EnableTimerGroup",
  "EnableTrigger",
  "EnableTriggerGroup",
  "ErrorDesc",
  "EvaluateSpeedwalk",
  "Execute",
  "ExportXML",
  "FixupEscapeSequences",
  "FixupHTML",
  "GenerateName",
  "GetAlias",
  "GetAliasInfo",
  "GetAliasList",
  "GetAliasOption",
  "GetAliasWildcard",
  "GetAlphaOption",
  "GetAlphaOptionList",
  "GetChatInfo",
  "GetChatList",
  "GetChatOption",
  "GetClipboard",
  "GetCommand",
  "GetCommandList",
  "GetConnectDuration",
  "GetCurrentValue",
  "GetDefaultValue",
  "GetEntity",
  "GetFrame",
  "GetHostAddress",
  "GetHostName",
  "GetInfo",
  "GetInternalCommandsList",
  "GetLineCount",
  "GetLineInfo",
  "GetLinesInBufferCount",
  "GetLoadedValue",
  "GetMainWindowPosition",
  "GetMapColour",
  "GetMappingCount",
  "GetMappingItem",
  "GetMappingString",
  "GetNotepadLength",
  "GetNotepadText",
  "GetNotepadWindowPosition",
  "GetNotes",
  "GetNoteStyle",
  "GetOption",
  "GetOptionList",
  "GetPluginAliasInfo",
  "GetPluginAliasList",
  "GetPluginID",
  "GetPluginInfo",
  "GetPluginList",
  "GetPluginName",
  "GetPluginTimerInfo",
  "GetPluginTimerList",
  "GetPluginTriggerInfo",
  "GetPluginTriggerList",
  "GetPluginVariable",
  "GetPluginVariableList",
  "GetQueue",
  "GetReceivedBytes",
  "GetRecentLines",
  "GetScriptTime",
  "GetSelectionEndColumn",
  "GetSelectionEndLine",
  "GetSelectionStartColumn",
  "GetSelectionStartLine",
  "GetSentBytes",
  "GetStyleInfo",
  "GetSysColor",
  "GetSystemMetrics",
  "GetTimer",
  "GetTimerInfo",
  "GetTimerList",
  "GetTimerOption",
  "GetTrigger",
  "GetTriggerInfo",
  "GetTriggerList",
  "GetTriggerOption",
  "GetTriggerWildcard",
  "GetUdpPort",
  "GetUniqueID",
  "GetUniqueNumber",
  "GetVariable",
  "GetVariableList",
  "GetWorld",
  "GetWorldById",
  "GetWorldID",
  "GetWorldIdList",
  "GetWorldList",
  "GetWorldWindowPosition",
  "GetWorldWindowPositionX",
  "GetXMLEntity",
  "Hash",
  "Help",
  "Hyperlink",
  "ImportXML",
  "Info",
  "InfoBackground",
  "InfoClear",
  "InfoColour",
  "InfoFont",
  "IsAlias",
  "IsConnected",
  "IsLogOpen",
  "IsPluginInstalled",
  "IsTimer",
  "IsTrigger",
  "LoadPlugin",
  "LogInput",
  "LogNotes",
  "LogOutput",
  "LogSend",
  "MakeRegularExpression",
  "MapColour",
  "MapColourList",
  "Mapping",
  "MoveMainWindow",
  "MoveNotepadWindow",
  "MoveWorldWindow",
  "MoveWorldWindowX",
  "MtRand",
  "MtSrand",
  "NormalColour",
  "Note",
  "NoteColour",
  "NoteColourBack",
  "NoteColourFore",
  "NoteColourName",
  "NoteColourRGB",
  "NoteHr",
  "NotepadColour",
  "NotepadFont",
  "NoteStyle",
  "Open",
  "OpenLog",
  "PasteCommand",
  "Pause",
  "PickColour",
  "PluginSupports",
  "PushCommand",
  "Queue",
  "ReadNamesFile",
  "Redraw",
  "ReloadPlugin",
  "RemoveBacktracks",
  "RemoveMapReverses",
  "Replace",
  "ReplaceNotepad",
  "Reset",
  "ResetStatusTime",
  "ResetTimer",
  "ResetTimers",
  "ReverseSpeedwalk",
  "RGBColourToName",
  "Save",
  "SaveNotepad",
  "SaveState",
  "SelectCommand",
  "Send",
  "SendImmediate",
  "SendNoEcho",
  "SendPush",
  "SendToNotepad",
  "SetAliasOption",
  "SetAlphaOption",
  "SetChanged",
  "SetChatOption",
  "SetClipboard",
  "SetCommand",
  "SetEntity",
  "SetInputFont",
  "SetNotes",
  "SetOption",
  "SetOutputFont",
  "SetStatus",
  "SetTimerOption",
  "SetTriggerOption",
  "SetVariable",
  "ShowInfoBar",
  "Simulate",
  "Sound",
  "SpeedWalkDelay",
  "SpellCheck",
  "SpellCheckCommand",
  "StripANSI",
  "Tell",
  "Trace",
  "TraceOut",
  "TranslateGerman",
  "Trim",
  "UdpListen",
  "UdpPortList",
  "UdpSend",
  "Version",
  "WorldAddress",
  "WorldName",
  "WorldPort",
  "WriteLog",
}

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #2 on Thu 29 Dec 2005 07:35 PM (UTC)
Message
Of course, you could adapt the idea slightly to fix up things like "if" to "If" (for VBscript), "endif" to "EndIf" and so on.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


10,370 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.