public void Init() { if (IsInit) { return; } IsInit = true; var lua = AppApplication.Lua; var dialogs = new Dialogs(); //选择器 lua["by"] = new By(); lua["context"] = AppApplication.Instance.ApplicationContext; //app 操作 lua["app"] = new LuaAppUtils(AppApplication.Instance); //设备信息 lua["device"] = new Device(); //弹窗 lua["dialogs"] = dialogs; //脚本系统 lua["engines"] = new Engines(); //事件系统 lua["events"] = new Api.Events(); //文件系统 lua["files"] = new LuaFiles(); //网络请求模块 lua["http"] = new HttpLua(); //顔色模塊 lua["colors"] = new Colors(); luaGlobal = new LuaGlobalMethod(AppApplication.Instance); var luaGlobalType = typeof(LuaGlobalMethod); var dialogsType = typeof(Dialogs); //加载lua可以调用C#框架函数 lua.LoadCLRPackage(); //注册lua全局函数 lua.RegisterFunction("sleep", luaGlobal, luaGlobalType.GetMethod("Sleep")); lua.RegisterFunction("currentPackage", luaGlobal, luaGlobalType.GetMethod("CurrentPackage")); lua.RegisterFunction("currentActivity", luaGlobal, luaGlobalType.GetMethod("CurrentActivity")); lua.RegisterFunction("setClip", luaGlobal, luaGlobalType.GetMethod("SetClip")); lua.RegisterFunction("getClip", luaGlobal, luaGlobalType.GetMethod("GetClip")); lua.RegisterFunction("toast", luaGlobal, luaGlobalType.GetMethod("Toast")); lua.RegisterFunction("toastLog", luaGlobal, luaGlobalType.GetMethod("ToastLog")); lua.RegisterFunction("waitForActivity", luaGlobal, luaGlobalType.GetMethod("WaitForActivity")); lua.RegisterFunction("waitForPackage", luaGlobal, luaGlobalType.GetMethod("WaitForPackage")); lua.RegisterFunction("exit", luaGlobal, luaGlobalType.GetMethod("Exit")); lua.RegisterFunction("print", luaGlobal, luaGlobalType.GetMethod("Print")); lua.RegisterFunction("log", luaGlobal, luaGlobalType.GetMethod("Print")); //点击 lua.RegisterFunction("click", luaGlobal, luaGlobalType.GetMethod("Click")); lua.RegisterFunction("longClick", luaGlobal, luaGlobalType.GetMethod("LongClick")); lua.RegisterFunction("press", luaGlobal, luaGlobalType.GetMethod("Press")); lua.RegisterFunction("swipe", luaGlobal, luaGlobalType.GetMethod("Swipe")); lua.RegisterFunction("gesture", luaGlobal, luaGlobalType.GetMethod("Gesture")); lua.RegisterFunction("gestures", luaGlobal, luaGlobalType.GetMethod("Gestures")); //弹窗 lua.RegisterFunction("alert", dialogsType, dialogsType.GetMethod("alert")); }
public void Init() { if (IsInit) { return; } IsInit = true; dynamic lua = new DynamicLua(); var dialogs = new Dialogs(); _luaGlobal = new LuaGlobalMethod(AppApplication.Instance); //元素选择器 lua.by = new By(); lua.context = AppApplication.Instance.ApplicationContext; //app 操作 lua.app = new LuaAppUtils(AppApplication.Instance); //设备信息 lua.device = new Api.Device(); //弹窗 lua.dialogs = dialogs; //脚本系统 lua.engines = new Engines(); //事件系统 lua.events = new Api.Events(); //文件系统 lua.files = new LuaFiles(); //网络请求模块 lua.http = new HttpLua(); //顔色模塊 lua.colors = new Colors(); //找图找色模块 lua.images = new Images(); //无障碍服务手势 lua.keys = new KeysApi(); //多媒体 lua.media = new Media(); //传感器 lua.sensors = new Sensors(); //本地存储 lua.storages = new SharedPreferences(); //线程模块 lua.threads = new ThreadApi(); var time = new TimerApi(); //定时器模块 lua.times = time; //注册lua全局函数 lua.sleep = new Action <int>(_luaGlobal.Sleep); lua.currentPackage = new Func <string>(_luaGlobal.CurrentPackage); lua.currentActivity = new Func <string>(_luaGlobal.CurrentActivity); lua.setClip = new Action <string>(_luaGlobal.SetClip); lua.getClip = new Func <string>(_luaGlobal.GetClip); lua.toast = new Action <string>(_luaGlobal.Toast); lua.toastLog = new Action <string>(_luaGlobal.ToastLog); lua.waitForActivity = new Action <string, int>(_luaGlobal.WaitForActivity); lua.waitForPackage = new Action <string, int>(_luaGlobal.WaitForPackage); lua.exit = new Action(_luaGlobal.Exit); lua.print = new Action <object>(_luaGlobal.Print); lua.log = new Action <object>(_luaGlobal.Print); //点击 lua.click = new Func <int, int, bool>(_luaGlobal.Click); lua.longClick = new Func <int, int, bool>(_luaGlobal.LongClick); lua.press = new Func <int, int, int, bool>(_luaGlobal.Press); lua.swipe = new Func <int, int, int, int, int, bool>(_luaGlobal.Swipe); lua.gesture = new Func <int, int[][], bool>(_luaGlobal.Gesture); lua.gestures = new Func <GestureDescription.StrokeDescription[], bool>(_luaGlobal.Gestures); //弹窗 lua.alert = new Action <string, string, Action>(dialogs.alert); //定时器 lua.setInterval = new Func <Action, long, string>(time.setInterval); lua.setTimeout = new Action <Action, long>(time.setTimeout); //加载文件 LoadScript(lua); AppApplication.Lua = lua; }