Difference between revisions of "Manual:Lua Functions"

From Mudlet
Jump to navigation Jump to search
Line 17: Line 17:
 
'''Miscellaneous Functions'''
 
'''Miscellaneous Functions'''
  
== Label/Window creation/manipulation Functions ==
+
= Label/Window creation/manipulation Functions =
== Table Functions ==
+
= Table Functions =
== String Functions ==
+
= String Functions =
=string.cut=
+
==string.cut==
 
string.cut(s, maxLen)
 
string.cut(s, maxLen)
  
Line 37: Line 37:
 
     echo("'" .. s .. "'")
 
     echo("'" .. s .. "'")
 
          
 
          
=string.enclose=
+
==string.enclose==
 
string.enclose(s, maxlevel)
 
string.enclose(s, maxlevel)
  
Line 46: Line 46:
 
     maxlevel:
 
     maxlevel:
  
=string.ends=
+
==string.ends==
 
string.ends(String, Suffix)
 
string.ends(String, Suffix)
  
Line 58: Line 58:
 
     [[Manual:Lua_Functions#String_Functions#string.starts|string.starts()]]  
 
     [[Manual:Lua_Functions#String_Functions#string.starts|string.starts()]]  
  
=string.findPattern=
+
==string.findPattern==
 
string.findPattern(text, pattern)
 
string.findPattern(text, pattern)
 
Return first matching substring or nil.
 
Return first matching substring or nil.
Line 84: Line 84:
 
     [[Manual:Lua_Functions#String_Functions#string.genNocasePattern|string.genNocasePattern()]]  
 
     [[Manual:Lua_Functions#String_Functions#string.genNocasePattern|string.genNocasePattern()]]  
  
=string.genNocasePattern=
+
==string.genNocasePattern==
 
string.genNocasePattern(s)
 
string.genNocasePattern(s)
  
Line 99: Line 99:
 
   case insensitive pattern string  
 
   case insensitive pattern string  
  
=string.starts=
+
==string.starts==
  
 
string.starts(String, Prefix)
 
string.starts(String, Prefix)
Line 109: Line 109:
 
     string.ends  
 
     string.ends  
  
=string.trim=
+
==string.trim==
  
 
string.trim (s)
 
string.trim (s)
Line 121: Line 121:
 
     echo("'" .. str .. "'")
 
     echo("'" .. str .. "'")
 
          
 
          
=string:split=
+
==string:split==
  
 
string:split(delimiter)
 
string:split(delimiter)
Line 142: Line 142:
 
     array with split strings  
 
     array with split strings  
  
=string:title=
+
==string:title==
  
 
string:title()
 
string:title()
Line 154: Line 154:
 
     test = string.title(test)
 
     test = string.title(test)
  
== Scripting Object Functions ==
+
= Scripting Object Functions =
== Mapper Functions ==
+
= Mapper Functions =
== Miscellaneous Functions ==
+
= Miscellaneous Functions =

Revision as of 08:07, 21 May 2011

Function Categories

Label/Window creation/manipulation Functions: These functions are used to construct custom user GUIs. They deal mainly with miniconsole/label/gauge creation and manipulation.

  createMiniConsole()
  createLabel()
  createGauge()

Table Functions: These functions are used to manipulate tables. Through them you can add to tables, remove values, check if a value is present in the table, check the size of a table, and more.

String Functions

Scripting Object Functions

Mapper Functions

Miscellaneous Functions

Label/Window creation/manipulation Functions

Table Functions

String Functions

string.cut

string.cut(s, maxLen)

Cut string to specified maximum length.

Parameters:

    s:
    maxLen:

Usage:

    Following call will return 'abc'.
    string.cut("abcde", 3)

You can easily pad string to certain length. Example bellow will print 'abcde ' e.g. pad/cut string to 10 characters.

    local s = "abcde"
    s = string.cut(s .. "          ", 10)   -- append 10 spaces
    echo("'" .. s .. "'")
       

string.enclose

string.enclose(s, maxlevel)

Enclose string by long brackets.

Parameters:

    s:
    maxlevel:

string.ends

string.ends(String, Suffix)

Test if string is ending with specified suffix.

Parameters:

    String:
    Suffix:

See also:

    string.starts() 

string.findPattern

string.findPattern(text, pattern) Return first matching substring or nil.

Parameters

   text:
   pattern:

Usage: Following example will print: "I did find: Troll" string.

   local match = string.findPattern("Troll is here!", "Troll")
   if match then
   echo("I did find: " .. match)
   end

This example will find substring regardless of case.

   local match = string.findPattern("Troll is here!", string.genNocasePattern("troll"))
   if match then
   echo("I did find: " .. match)
   end

Return value:

   nil or first matching substring 

See also:

   string.genNocasePattern() 

string.genNocasePattern

string.genNocasePattern(s)

Generate case insensitive search pattern from string.

Parameters

   s:

Usage: Following example will generate and print "123[aA][bB][cC]" string.

  echo(string.genNocasePattern("123abc"))

Return value:

  case insensitive pattern string 

string.starts

string.starts(String, Prefix) Test if string is starting with specified prefix. Parameters:

    String:
    Prefix:

See also:

    string.ends 

string.trim

string.trim (s) Trim string (remove all white spaces around string).

Parameters:

    s:

Usage: Example will print 'Troll is here!'.

    local str = string.trim("  Troll is here!  ")
    echo("'" .. str .. "'")
        

string:split

string:split(delimiter) Splits a string into a table by the given delimiter.

Parameters:

   delimiter:

Usage: Split string by ", " delimiter.

   names = "Alice, Bob, Peter"
   name_table = names:split(", ")
   display(name_table)

Previous code will print out:

   table {
   1: 'Alice'
   2: 'Bob'
   3: 'Peter'
   }

Return value:

   array with split strings 

string:title

string:title() Capitalize first character in a string.

Usage: Variable testname is now Anna.

    testname = string.title("anna")

Example will set test to "Bob".

    test = "bob"
    test = string.title(test)

Scripting Object Functions

Mapper Functions

Miscellaneous Functions