StendhalScripting/LuaAPI: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
imported>AntumDeluge
logger: add details
imported>AntumDeluge
string & table supplemental methods
Line 240: Line 240:


The [https://docs.oracle.com/javase/8/docs/api/java/awt/Color.html java.awt.Color] class.
The [https://docs.oracle.com/javase/8/docs/api/java/awt/Color.html java.awt.Color] class.

= Supplemental Methods =

A few convenience methods are added to make scripting easier.

== String Manipulation ==

The following methods have been added to the built-in Lua [https://www.lua.org/manual/5.3/manual.html#6.4 string] library.

* ''<span style="color:green;">string.startsWith</span>(st, prefix)''
** Checks if a string begins with a set of characters.
** <span style="color:darkgreen; text-style=italic;">st:</span> The string to be checked.
** <span style="color:darkgreen; text-style=italic;">prefix:</span> The prefix to be compared with.
** returns: <code>true</code> if <code>prefix</code> matches the beginning characters of <code>st</code>.
* ''<span style="color:green;">string.beginsWith</span>(st, prefix)''
** This is just an alias for <code>string.startsWith</code>.
* ''<span style="color:green;">string.endsWith</span>(st, suffix)''
** Checks if a string ends with a set of characters.
** <span style="color:darkgreen; text-style=italic;">st:</span> The string to be checked.
** <span style="color:darkgreen; text-style=italic;">suffix:</span> The suffix to be compared with.
** returns: <code>true</code> if <code>suffix</code> matches then end characters of <code>st</code>.
* ''<span style="color:green;">string.trim</span>(st)''
** Removes leading & trailing whitespace from a string.
** <span style="color:darkgreen; text-style=italic;">st:</span> The string to be trimmed.
** returns: Trimmed string.
* ''<span style="color:green;">string.ltrim</span>(st)''
** Removes leading whitespace from a string.
** <span style="color:darkgreen; text-style=italic;">st:</span> The string to be trimmed.
** returns: Trimmed string.
* ''<span style="color:green;">string.rtrim</span>(st)''
** Removes trailing whitespace from a string.
** <span style="color:darkgreen; text-style=italic;">st:</span> The string to be trimmed.
** returns: Trimmed string.


== Table Manipulation ==

The following methods have been added to the built-in Lua [https://www.lua.org/manual/5.3/manual.html#6.6 table] library.

* ''<span style="color:green;">table.clean</span>(tbl)''
** Removes <code>nil</code> values from a table.
** <span style="color:darkgreen; text-style=italic;">tbl:</span> The table to be cleaned.
** returns: Copy of <code>tbl</code> with <code>nil</code> values removed.
* ''<span style="color:green;">table.concat</span>(tbl1, tbl2)''
** Merges the contents of one table into another.
** <span style="color:darkgreen; text-style=italic;">tbl1:</span> The table receiving the new content.
** <span style="color:darkgreen; text-style=italic;">tbl2:</span> The table containing the content to be copied.