-
Notifications
You must be signed in to change notification settings - Fork 2
Changes
There are several changes that were made to the language to make it more compatible with .NET. Most changes were to the runtime, so the code will not change much, if at all; however, the results of functions and the handling of variables have changed a little. All Lua 5.2 code is compatible with this library and will likely work properly. This library defines a global variable called _NET which is a string of the current version. To have code run only if it is compiled by this library, check if it is not nil.
This section describes the changes made to the code language. Because Lua is a dynamically typed language and .NET is very statically typed language, there are some changes to how values are handled.
.NET allows for two methods to have the same name and perform different tasks, assuming that their signatures are different. However, Lua does not technically allow this. So when you try to call a user-defined method from Lua code, the Library has to determine which method to actually call. When two methods match the given parameters, then an AmbiguousMatchException is thrown. To allow the user to call a specific overload of a method, there was a change to the language. The grave character (`) is used in method calls to define a specific overload. After the name of the method, place a grave followed by the index of the overload:
var.Call`3(2, nil)The index is a zero-based integer. If using a global method, then the order is the order they were added. If calling an instance method, it is the order returned by Type.GetMethods(), which is usually the order that they are defined.
This section describes the changes made to the libraries. These may only me internal or subtle differences. If it says that a function has moved to another library, it means that you need to specify the flag in LuaLibraries to register the function, it still has the same name.
assert - The function throws a AssertException when the first argument is false or nil.
collectgarbage - If the first argument is 'collect', the second argument can be the number 0, 1, or 2 and will call GC.Collect with the respective argument, if missing will call GC.Collect(). If the first argument is 'count' will return GC.GetTotalMemory and that value modulo 1024. This represents the total memory, in bytes by the hosting application. If the first argument is 'isrunning' the function will return true. Any other option will throw a System.NotSupportedException.
dofile - Moved to IO. No longer accepts zero arguments. Demands IOPermissions in the specified directory.
error - Throws a System.Exception with the specified message. Ignores the optional second argument.
load - Moved to IO. Ignores the second argument. Mode can only be nil or the string 't', cannot be binary. New argument, number 5, specifies whether the new environment should also have the user-defined functions and types of the current environment, can be true or false.
loadfile - Moved to IO. Demands IOPermission in specified directory. Mode can only be nil or the string 't', cannot be binary. New argument, number 5, specifies whether the new environment should also have the user-defined functions and types of the current environment, can be true or false.
pcall - Catches any thrown exceptions in specified function. If there is an error, returns false, the exception's message, and the exception object as UserData.
xpcall - Removed, not supported.
This library uses System.String to manipulate strings, so it supports Unicode characters and assumes multi-byte chars. Indexes are the same as in the Language Definition, 1 is the first letter and negative indices count from the end of the string (i.e. -1 is the last char). Indices also refer to the char index, not the byte index. If you do not include LuaLibraries.String in LuaSettings, the global string will point to System.String and will allow you to call the static members in it (see Maintaining Visibility).
string.char - Allows surrogate pairs by specifying them as an integer as in char. Also allows specifying Unicode code points.
string.dump - Removed, not supported.
string.find - Uses System.Text.RegularExpressions.Regex to get the matches.
string.format - Uses .NET format specification.
string.gmatch - Uses System.Text.RegularExpressions.Regex to get the matches.
string.gsub - Uses System.Text.RegularExpressions.Regex to get the matches.
string.lower - Uses CultureInfo.CurrentCulture to make the conversion.
string.match - Uses System.Text.RegularExpressions.Regex to get the matches.
string.upper - Uses CultureInfo.CurrentCulture to make the conversion.
This library simply converts the arguments and passes them to the respective function in System.Math. There are no changes to this library, but there is something to be aware of for math.random and math.randomseed. This library uses a static System.Random field to get random values. An exclusive lock is acquired each call to ensure thread safety. Calling math.randomseed will create a new System.Random object with the specified seed, must be an integer. Also, math.huge returns double.PositiveInfinity.
This library requires the respective System.IOPermissions to work. Permissions are Demand'ed by System.IO.File. The stream object returned by the functions here are a table with a key of "Stream" that contains the System.IO.Stream object. All functions will accept a table with that member or a System.IO.Stream object.
io.popen - Removed, not supported. Expose System.Diagnostics.Process to create processes.
io.lines AND file:lines - If first argument is a string that does not start with '*', a System.IO.Stream object, or a table with a 'Stream' it will use that as the stream, otherwise it will use io.input(). Make sure to use file:lines because file.lines will work and will use io.input() as the stream.
io.type - No longer returns "closed file" cannot determine if the file has been closed.
file:setvbuf - Removed, not supported. Uses the buffering specified in the given System.IO.Stream object.
os.clock - Starts a System.Diagnostics.Stopwatch when the first Lua is created, returns the time in seconds since then.
os.execute - Removed, not supported.
os.rename - Uses File.Move or Directory.Move to rename the file/directory. Can be used to move as well to rename.
os.setlocale - Ignores optional second argument, sets Thread.CurrentThread.CurrentCulture to the culture specified by the first argument. Returns that value if the first argument is nil. Make sure to call on main thread and not in a coroutine.
os.time - Returns the DateTime.Ticks that represents the specified time. Argument can be a table with the required fields, a DateTime structure, or a DateTimeOffset structure.