-
Notifications
You must be signed in to change notification settings - Fork 1
.NET Types
Kevin Zhao edited this page Jan 25, 2018
·
2 revisions
.NET types can be imported using the ImportType
or ImportNamespace
functions:
lua.ImportType(typeof(List<>));
lua.ImportNamespace("System.Collections.Generic");
These types will be imported as globals, which you can access using their 'friendly' name. For example, List<>
will be imported as List
, and Dictionary<,>
will be imported as Dictionary
. You can then use them transparently like normal .NET types:
lua.ImportType(typeof(Console));
lua.ImportType(typeof(DateTime));
lua.DoString("Console.WriteLine(DateTime.UtcNow)");
.NET Types can be imported from Lua using the using
function:
lua.DoString(@"
using 'System'
Console.WriteLine('Hello world!')");
You can construct .NET objects by 'calling' the type:
lua.ImportNamespace("System.IO");
lua.DoString("sr = StreamReader('path.txt')");
You can construct generic types by 'calling' the type with the type arguments. Note that this can be extended indefinitely:
lua.ImportNamespace("System");
lua.ImportNamespace("System.Collections.Generic");
lua.DoString("list = List(List(Dictionary(Int32, Int32)))()");