I want to pass whole class from c# code to lua, so I can create in LUA a new object and use its methods, fields and so. When it's done, I'd like to know if it's possible to use objects in lua, which were created in a c# code and then passed somehow to lua.
Here's my code: atm, its not possible to create in my luainterface object of class Person1 and then use its function when I enter say() into lua scripter (without creating any object there), I'm getting output of Person2.say()
using System;
using LuaInterface;
using System.Reflection;
namespace ConsoleApplication
{
public class Person1
{
public void say()
{
Console.WriteLine("person1 says: hehe");
}
}
public class Person2
{
public void say()
{
Console.WriteLine("person2 says: hihi");
}
}
class Class1
{
static void Main(string[] args)
{
Lua lua_compiler = new Lua();
Person1 person1 = new Person1();
Person2 person2 = new Person2();
lua_compiler.RegisterFunction("say", person1, person1.GetType().GetMethod("say"));
lua_compiler.RegisterFunction("say", person2, person2.GetType().GetMethod("say"));
while (true)
{
string line = Console.ReadLine();
try { lua_compiler.DoString(line); }
catch { }
}
}
}
}