Files
mapo-mono/MP.MONO.DECODER/Program.cs
T
2022-03-14 11:57:54 +01:00

38 lines
1.1 KiB
C#

using NLua;
using MP.MONO.DECODER;
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Start DECODER with LUA integration!");
Lua state;
static double Compute(double x)
{
return x * (x - 1);
}
var myobj = new MyClass();
myobj.IntegerProperty = 17;
state = new Lua();
state["var1"] = "someValue";
state["obj"] = myobj;
state["compute"] = new Func<double, double>(Compute);
// Will print "output: someValue"
state.DoString(" print('output: ' .. var1) ");
// Will print 18
state.DoString(" print(obj.IntegerProperty + 1) ");
// Will print "Doing something: hello"
state.DoString(" obj:DoSomething('hello') ");
// Will print "-0.1875"
state.DoString(" print(compute(0.25)) ");
// Reading values back
state.DoString(" x = compute(0.75) ");
state.DoString(" y = 2.0 * (obj.IntegerProperty * x) ");
string luaPath = Path.Combine(Directory.GetCurrentDirectory(), "lua", "prova.lua");
state.DoFile(luaPath);
double x = state.GetNumber("x");
double y = state.GetNumber("y");
// Will print: x = -0.1875, y = -6.375
Console.WriteLine($"x = {x}, y = {y}");