public static void RegisterNLuaBox(Lua context) { context.RegisterLuaDelegateType (typeof (EventHandler<EventArgs>), typeof (LuaEventArgsHandler)); context.RegisterLuaDelegateType (typeof (EventHandler), typeof (LuaEventArgsHandler)); context.RegisterLuaDelegateType (typeof (EventHandler<UIButtonEventArgs>), typeof (LuaButtonEventArgsHandler)); context.RegisterLuaClassType (typeof (UIViewController), typeof (NLuaBoxUIViewControllerBinder)); }
public static void RegisterNLuaBox(Lua context) { context.RegisterLuaDelegateType (typeof (EventHandler<EventArgs>), typeof (LuaEventArgsHandler)); context.RegisterLuaDelegateType (typeof (EventHandler), typeof (LuaEventArgsHandler)); context.RegisterLuaDelegateType (typeof (EventHandler<UIButtonEventArgs>), typeof (LuaButtonEventArgsHandler)); context.RegisterLuaDelegateType (typeof(NSAction), typeof(LuaNSActionHandler)); context.RegisterLuaClassType (typeof (UIViewController), typeof (NLuaBoxUIViewControllerBinder)); context.RegisterLuaClassType (typeof (UITableViewSource), typeof (NLuaBoxUITableViewSourceBinder)); context.RegisterLuaClassType (typeof (JLTextViewController), typeof (NLuaBoxDetailLuaViewController)); context.RegisterLuaClassType (typeof (DialogViewController), typeof (NLuaBoxDialogViewControllerBinder)); context.RegisterLuaClassType (typeof (UITableViewController), typeof (NLuaBoxUITableViewControllerBinder)); context.RegisterFunction ("CreateListString", typeof (NLuaBoxBinder).GetMethod ("CreateListString")); }
public static void RegisterNLuaDelegate(Lua context) { //Only For IOS context.RegisterLuaDelegateType(typeof(EventTriggerListener.VoidDelegate), typeof(CallbackLuaFunction<GameObject>)); context.RegisterLuaDelegateType(typeof(Action<object>), typeof(CallbackLuaFunction<object>)); context.RegisterLuaDelegateType(typeof(Action), typeof(CallbackLuaFunction)); context.RegisterLuaDelegateType(typeof(Callback), typeof(CallbackLuaFunction)); context.RegisterLuaDelegateType(typeof(Callback<object>), typeof(CallbackLuaFunction<object>)); context.RegisterLuaDelegateType(typeof(Callback<string, AssetBundle>), typeof(CallbackLuaFunction<string, AssetBundle>)); }
public void TestEventException () { using (Lua lua = new Lua ()) { //Register a C# function MethodInfo testException = this.GetType ().GetMethod ("_TestException", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance, null, new Type [] { typeof(float), typeof(float) }, null); lua.RegisterFunction ("Multiply", this, testException); lua.RegisterLuaDelegateType (typeof(EventHandler<EventArgs>), typeof(LuaEventArgsHandler)); //create the lua event handler code for the entity //includes the bad code! lua.DoString ("function OnClick(sender, eventArgs)\r\n" + "--Multiply expects 2 floats, but instead receives 2 strings\r\n" + "Multiply(asd, es)\r\n" + "end"); //create the lua event handler code for the entity //good code //lua.DoString("function OnClick(sender, eventArgs)\r\n" + // "--Multiply expects 2 floats\r\n" + // "Multiply(2, 50)\r\n" + // "end"); //Create the event handler script lua.DoString ("function SubscribeEntity(e)\r\ne.Clicked:Add(OnClick)\r\nend"); //Create the entity object Entity entity = new Entity (); //Register the entity object with the event handler inside lua LuaFunction lf = lua.GetFunction ("SubscribeEntity"); lf.Call (new object [1] { entity }); try { //Cause the event to be fired entity.Click (); //failed Assert.AreEqual(true, false); } catch (LuaException) { //passed Assert.AreEqual (true, true); } } }
public void LuaDelegateReferenceTypesByRefParam () { using (Lua lua = new Lua ()) { lua.RegisterLuaDelegateType (typeof(TestDelegate7), typeof(LuaTestDelegate7Handler)); lua.DoString ("luanet.load_assembly('NLuaTest')"); lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')"); lua.DoString ("test=TestClass()"); lua.DoString ("function func(x,y) return TestClass(x+y.testval); end"); lua.DoString ("a=test:callDelegate7(func)"); int a = (int)lua.GetNumber ("a"); Assert.AreEqual (5, a); //Console.WriteLine("delegate returned: "+a); } }
public void LuaDelegateValueTypesOutParam () { using (Lua lua = new Lua ()) { lua.RegisterLuaDelegateType (typeof(TestDelegate2), typeof(LuaTestDelegate2Handler)); lua.DoString ("luanet.load_assembly('NLuaTest')"); lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')"); lua.DoString ("test=TestClass()"); lua.DoString ("function func(x) return x,x*2; end"); lua.DoString ("test=TestClass()"); lua.DoString ("a=test:callDelegate2(func)"); int a = (int)lua.GetNumber ("a"); Assert.AreEqual (6, a); //Console.WriteLine("delegate returned: "+a); } }
public static void RegisterNLuaDelegate(Lua context) { //主要针对ios,aot下不能有动态模板映射,当kera模式在ios发布平台的时候 context.RegisterLuaDelegateType(typeof(EventListener.VoidDelegate), typeof(CallbackLuaFunction<GameObject>)); context.RegisterLuaDelegateType(typeof(Action<object>), typeof(CallbackLuaFunction<object>)); context.RegisterLuaDelegateType(typeof(Action), typeof(CallbackLuaFunction)); context.RegisterLuaDelegateType(typeof(Callback), typeof(CallbackLuaFunction)); context.RegisterLuaDelegateType(typeof(Callback<object>), typeof(CallbackLuaFunction<object>)); context.RegisterLuaDelegateType(typeof(Callback<string, AssetBundle>), typeof(CallbackLuaFunction<string, AssetBundle>)); context.RegisterLuaDelegateType(typeof(DownloadProgressChangedEventHandler), typeof(CallbackLuaFunction<object, DownloadProgressChangedEventArgs>)); context.RegisterLuaDelegateType(typeof(AsyncCompletedEventHandler), typeof(CallbackLuaFunction<object, AsyncCompletedEventArgs>)); context.RegisterLuaDelegateType(typeof(UploadProgressChangedEventHandler), typeof(CallbackLuaFunction<object, UploadProgressChangedEventArgs>)); context.RegisterLuaDelegateType(typeof(UploadStringCompletedEventHandler), typeof(CallbackLuaFunction<object, UploadStringCompletedEventArgs>)); }