private static int AddGlobalObject(LuaManager Instance,IntPtr l) { // get method arguments int objId = (int)LuaApi.lua_tonumber(l,3); Object obj = LuaManager.Instance.GetObjectT<Object>(objId); // call method Int32 methodRetVar = Instance.AddHeapObject(obj); LuaApi.lua_pushnumber(l,methodRetVar); return 1; }
private static int GetObject(LuaManager Instance,IntPtr l) { // get method arguments Int32 id = (Int32)LuaApi.lua_tonumber(l,3); // call method Object methodRetVar = Instance.GetObject(id); int nRetObjectId = LuaManager.Instance.PushStackObject(methodRetVar); LuaApi.lua_pushnumber(l,nRetObjectId); return 1; }
private static int update_desc(int L) { if (!LuaCommon.CheckAndShowArgsError(L, LConst.Function, LConst.NTable)) { return(0); } int callbackF = -1; Dictionary <string, string> dic = null; if (Lua.Lua_istable(L, -1)) { dic = new Dictionary <string, string>(); Lua.Lua_pushnil(L); while (Lua.Lua_next(L, -2) != 0) { String value = Lua.Lua_tostring(L, -1).ToString(); String key = Lua.Lua_tostring(L, -2).ToString(); dic[key] = value; Lua.Lua_pop(L, 1); } Lua.Lua_pop(L, 1); } if (Lua.Lua_isfunction(L, -1)) { callbackF = Lua.LuaL_ref(L, Lua._LUA_REGISTRYINDEX); } Action <int> callBack = null; if (callbackF != -1) { callBack = (mustUpdate) => { LuaManager.GetLuaManager(L).ExecuteCallBackFunctionWithParam(callbackF, mustUpdate); }; } MethodInfo mi = LuaManager.GetLuaManager(L).DetailV_.GetType().GetMethod("OfflineUpdate_Desc", new Type[] { typeof(Action <int>), typeof(Dictionary <string, string>) }); if (mi != null) { mi.Invoke(LuaManager.GetLuaManager(L).DetailV_, new object[] { callBack, dic }); } return(0); }
public void LoadLuaScript(string fullPath) { if (string.IsNullOrEmpty(fullPath)) { return; } FullPath = fullPath; if (!component) { string className = System.IO.Path.GetFileNameWithoutExtension(FullPath); luaTable = LuaManager.GetTable(className); if (luaTable == null) { LuaManager.DoFile(FullPath); if (!string.IsNullOrEmpty(className)) { luaTable = LuaManager.GetTable(className); if (luaTable == null) { Util.LogError("Game", string.Format("没有找到{0}对应的lua表, 请确保文件名和lua表名一致", className)); } } } } else { object[] luaRet = LuaManager.DoFile(FullPath); if (luaRet != null && luaRet.Length >= 1) { // 约定:第一个返回的Table对象作为Lua模块 luaTable = luaRet[0] as LuaTable; } else { Util.LogError("Game", "Lua脚本没有返回Table对象:" + FullPath); } } if (luaTable != null) { luaTable["transform"] = transform; luaTable["gameObject"] = gameObject; } Call("Awake"); }
static void GenProtocol() { LuaManager luaMgr = new LuaManager(); Action <string, string> gen = null; XLua.LuaTable protocol = null; try { luaMgr.Init(); luaMgr.AddSearchPath(EditorConst.EditorDir); luaMgr.AddSearchPath(EditorConst.ScriptDir); protocol = luaMgr.GetTable("Protocol"); List <string> files = new List <string>(Directory.GetFiles(c2s_dir)); files.Add(notice_file); StringBuilder des = new StringBuilder(); for (int i = 0; i < files.Count; i++) { string content = File.ReadAllText(files[i]); des.AppendFormat("{0}\n", content); } string rawProto = File.ReadAllText(protoc_file); string desString = string.Format("return [[\n{0}]]", des.ToString()); gen = protocol.Get <Action <string, string> >("GenProtocol"); gen(desString, rawProto); gen = null; string messageString = protocol.Get <Func <string> >("GetMessageString")(); string protoString = protocol.Get <Func <string> >("GetProtoString")(); string dir = EditorConst.ScriptDir + "/Protocol/"; File.WriteAllText(dir + "Descriptor.lua", desString); File.WriteAllText(dir + "Protocol.lua", protoString); File.WriteAllText(dir + "Message.lua", messageString); } catch (Exception e) { Debug.LogErrorFormat("{0}\n{1}", e.Message, e.StackTrace); } finally { protocol.Dispose(); protocol = null; luaMgr.Dispose(); } }
/// <summary> /// 355 eval /// lua脚本 /// </summary> public bool command_evalScript() { string src = this.currentParam[0]; Debug.Log(src); XLua.LuaTable scriptEnv = LuaManager.getInterpreterEnvTable(this); object[] results = LuaManager.LuaEnv.DoString(src, string.Format("event_eval_{0}", this.eventId), scriptEnv); if (results != null && results.Length > 0) { return((bool)results[0]); } return(true); }
public string LoadConfigFile(string configName) { ConfigRequest configReq = null; if (!HasConfigRequest(configName, out configReq)) { return(""); } #if RESOURCE_DEBUG TextAsset text = Resources.Load <TextAsset>(configReq.ConfigResourcePath); return(text.text); #elif UNITY_ANDROID return(FileManager.LoadFileWithString(configReq.ConfigResourcePath + ".txt")); #else return(FileManager.LoadFileWithString(LuaManager.GetConfigPath() + "/" + configReq.ConfigResourcePath + ".txt")); #endif }
static int get_luaMgr(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); GameManager obj = (GameManager)o; LuaManager ret = obj.luaMgr; ToLua.Push(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index luaMgr on a nil value" : e.Message)); } }
static int GetTable(IntPtr L) { try { ToLua.CheckArgsCount(L, 3); LuaManager obj = (LuaManager)ToLua.CheckObject(L, 1, typeof(LuaManager)); string arg0 = ToLua.CheckString(L, 2); bool arg1 = LuaDLL.luaL_checkboolean(L, 3); LuaInterface.LuaTable o = obj.GetTable(arg0, arg1); ToLua.Push(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
private static int LuaGC(IntPtr L) { int result; try { ToLua.CheckArgsCount(L, 1); LuaManager luaManager = (LuaManager)ToLua.CheckObject(L, 1, typeof(LuaManager)); luaManager.LuaGC(); result = 0; } catch (Exception e) { result = LuaDLL.toluaL_exception(L, e, null); } return(result); }
static int get(int L) { if (!LuaCommon.CheckAndShowArgsError(L, LConst.String)) { return(0); } string key = Lua.Lua_tostring(L, 2); var value = RYTDatabase.GetKVData(key); if (value != null) { if (value is string) { Lua.Lua_pushstring(L, value.ToString()); } else if (value is double) { Lua.Lua_pushnumber(L, (double)value); } else if (value is Boolean) { int result = (int)value; Lua.Lua_pushboolean(L, result); } else { List <KeyValuePair <string, string> > list = value as List <KeyValuePair <string, string> >; if (list != null && list.Count > 0) { Lua.Lua_newtable(L); for (int i = 0; i < list.Count; i++) { LuaManager.PushValueByType(L, list[i].Key); LuaManager.PushValueByType(L, list[i].Value); Lua.Lua_rawset(L, -3); } } } } else { Lua.Lua_pushnil(L); } return(1); }
static int CallFunction(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); LuaManager obj = (LuaManager)ToLua.CheckObject <LuaManager>(L, 1); string arg0 = ToLua.CheckString(L, 2); object[] arg1 = ToLua.ToParamsObject(L, 3, count - 2); object[] o = obj.CallFunction(arg0, arg1); ToLua.Push(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int __CreateInstance(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); if (LuaAPI.lua_gettop(L) == 1) { LuaManager gen_ret = new LuaManager(); translator.Push(L, gen_ret); return(1); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } return(LuaAPI.luaL_error(L, "invalid arguments to LuaManager constructor!")); }
static int passwordEncryption(int L) { if (!LuaCommon.CheckAndShowArgsError(L, LConst.Table, LConst.Table, LConst.Function)) { return(0); } Dictionary <String, object> parameters = null; bool isTable = Lua.Lua_istable(L, 2); if (isTable) { parameters = new Dictionary <String, object>(); Lua.Lua_pushnil(L); while (Lua.Lua_next(L, 2) != 0) { String value = Lua.Lua_tostring(L, -1).ToString(); String key = Lua.Lua_tostring(L, -2).ToString(); parameters[key] = value; Lua.Lua_pop(L, 1); } } Dictionary <String, String> modes = null; isTable = Lua.Lua_istable(L, 3); if (isTable) { modes = new Dictionary <String, String>(); Lua.Lua_pushnil(L); while (Lua.Lua_next(L, 3) != 0) { String value = Lua.Lua_tostring(L, -1).ToString(); String key = Lua.Lua_tostring(L, -2).ToString(); modes[key] = value; Lua.Lua_pop(L, 1); } } int callbackF = Lua.LuaL_ref(L, Lua._LUA_REGISTRYINDEX); object page = LuaManager.GetLuaManager(L).DetailV_; MethodInfo pe = page.GetType().GetMethod("passwordEncryption"); Object[] pars = new Object[] { parameters, modes, callbackF }; pe.Invoke(page, pars); return(0); }
public OverlayProfileModel(DeviceManager deviceManager, LuaManager luaManager, AudioCaptureManager audioCaptureManager) : base(deviceManager, luaManager) { Settings = SettingsProvider.Load <OverlayProfileSettings>(); DataModel = new OverlayProfileDataModel(); var defaultPlayback = MMDeviceEnumerator.TryGetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); if (defaultPlayback != null) { _endPointVolume = AudioEndpointVolume.FromDevice(defaultPlayback); } audioCaptureManager.AudioDeviceChanged += OnAudioDeviceChanged; Enable(); }
public WoWModel(DeviceManager deviceManager, LuaManager luaManager, WowPacketScanner packetScanner, MetroDialogService dialogService) : base(deviceManager, luaManager) { Settings = SettingsProvider.Load <WoWSettings>(); DataModel = new WoWDataModel(); ProcessNames.Add("Wow-64"); _packetScanner = packetScanner; _dialogService = dialogService; _packetScanner.RaiseDataReceived += (sender, args) => HandleGameData(args.Command, args.Data); FindWoW(); // I simply cannot be sure wether this addon will bring people's accounts in trouble so // lets remove it whenever Artemis isn't running the WoW module. // (This also means the addon isnt left behind should the user uninstall Artemis.) RemoveAddon(); }
public override void Execute(IMessage message) { //-----------------关联命令----------------------- PlotFacade.Instance.RegisterCommand(NotiConst.DISPATCH_MESSAGE, typeof(SocketCommand)); //-----------------初始化管理器----------------------- luaMgr = PlotFacade.Instance.AddManager <LuaManager>(); PlotFacade.Instance.AddManager <SoundManager>(); PlotFacade.Instance.AddManager <TimerManager>(); PlotFacade.Instance.AddManager <NetworkManager>(); PlotFacade.Instance.AddManager <ThreadManager>(); // AppFacade.Instance.AddManager<GameManager>(); PlotFacade.Instance.AddManager <SceneStageManager>(); //PlotFacade.Instance.AddManager<CutsceneManager>(); LuaStart(); }
static int set_luaMgr(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); GameManager obj = (GameManager)o; LuaManager arg0 = (LuaManager)ToLua.CheckUnityObject(L, 2, typeof(LuaManager)); obj.luaMgr = arg0; return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index luaMgr on a nil value" : e.Message)); } }
/** * path:读取文件的路径 * content:读取文件的内容 */ public static string LoadFileWithString(string path) { #if UNITY_ANDROID && !UNITY_EDITOR int size = 0; IntPtr p = IntPtr.Zero; LuaInterface.LuaDLL.getAsset(path, out p, out size); if (p != IntPtr.Zero) { byte[] content = new byte[size]; Marshal.Copy(p, content, 0, size); LuaInterface.LuaDLL.freeObj(p); Debug.Log("path is " + path + " size is " + size + " data " + content.ToString()); return(System.Text.Encoding.UTF8.GetString(content)); } else { Debug.Log(string.Format("Read file {0} failed", path)); } return(""); #else //使用流的形式读取 string content = null; StreamReader sr = null; try { string filepath = LuaManager.GetScriptPath() + "/" + path; sr = File.OpenText(filepath); } catch (Exception e) { //路径与名称未找到文件则直接返回空 #if LOG_DEBUG Debug.Log("Failed to open file " + path + " Error : " + e.Message); #endif return(""); } content = sr.ReadToEnd(); //关闭流 sr.Close(); //销毁流 sr.Dispose(); return(content); #endif }
/// <summary> /// 同步网络请求 /// </summary> /// <param name="lua"></param> /// <returns></returns> static int postSyn(int L) { if (!LuaCommon.CheckAndShowArgsError(L, LConst.Table, LConst.String, LConst.String)) { Lua.Lua_pushnil(L); return(1); } int num = Lua.Lua_gettop(L); if (num == 4) { Dictionary <String, String> headers = new Dictionary <string, string>(); bool isTable = Lua.Lua_istable(L, 2); if (isTable) { Lua.Lua_pushnil(L); while (Lua.Lua_next(L, 2) != 0) { String value = Lua.Lua_tostring(L, -1).ToString(); String key = Lua.Lua_tostring(L, -2).ToString(); headers[key] = value; Lua.Lua_pop(L, 1); } } string url = Lua.Lua_tostring(L, 3).ToString(); string body = string.Empty; if (Lua.Lua_isstring(L, 4)) { body = Lua.Lua_tostring(L, 4).ToString(); } object page = LuaManager.GetLuaManager(L).DetailV_; MethodInfo methods = page.GetType().GetMethod("postSyn"); Object[] pars = new Object[] { headers, url, body }; String result = (String)methods.Invoke(page, pars); Lua.Lua_pushstring(L, result); } else { Lua.Lua_pushnil(L); } return(1); }
/// <summary> /// 程序启动 /// </summary> public void AppLaunch() { DontDestroyOnLoad(gameObject); SetResourceLoadType(); //设置资源加载类型 ResourcesConfigManager.Initialize(); //资源路径管理器启动 MemoryManager.Init(); //内存管理初始化 Timer.Init(); //计时器启动 InputManager.Init(); //输入管理器启动 #if !UNITY_WEBGL UIManager.Init(); //UIManager启动 #else UIManager.InitAsync(); //异步加载UIManager #endif ApplicationStatusManager.Init(); //游戏流程状态机初始化 GlobalLogicManager.Init(); //初始化全局逻辑 if (AppMode != AppMode.Release) { GUIConsole.Init(); //运行时Console DevelopReplayManager.OnLunchCallBack += () => { #if USE_LUA LuaManager.Init(); #endif InitGlobalLogic(); //全局逻辑 ApplicationStatusManager.EnterTestModel(m_Status); //可以从此处进入测试流程 }; DevelopReplayManager.Init(m_quickLunch); //开发者复盘管理器 } else { Log.Init(false); //关闭 Debug #if USE_LUA LuaManager.Init(); #endif InitGlobalLogic(); //全局逻辑 ApplicationStatusManager.EnterStatus(m_Status); //游戏流程状态机,开始第一个状态 } }
/// <summary> /// 程序启动 /// </summary> public void AppLaunch() { DontDestroyOnLoad(gameObject); SetResourceLoadType(); //设置资源加载类型 ResourcesConfigManager.Initialize(); //资源路径管理器启动 MemoryManager.Init(); //内存管理初始化 HeapObjectPool.Init(); Timer.Init(); //计时器启动 InputManager.Init(); //输入管理器启动 UIManager.Init(); //UIManager启动 ApplicationStatusManager.Init(); //游戏流程状态机初始化 GlobalLogicManager.Init(); //初始化全局逻辑 if (m_AppMode != AppMode.Release) { GUIConsole.Init(); //运行时Console DevelopReplayManager.OnLunchCallBack += () => { if (m_useLua) { LuaManager.Init(); } InitGlobalLogic(); //全局逻辑 ApplicationStatusManager.EnterTestModel(m_Status); //可以从此处进入测试流程 }; DevelopReplayManager.Init(m_quickLunch); //开发者复盘管理器 } else { Log.Init(false); //关闭 Debug if (m_useLua) { LuaManager.Init(); } InitGlobalLogic(); //全局逻辑 ApplicationStatusManager.EnterStatus(m_Status); //游戏流程状态机,开始第一个状态 } }
/// <summary> /// 初始化游戏管理器 /// </summary> void Start() { DontDestroyOnLoad(gameObject); //防止销毁自己 mLuaManager = gameObject.GetComponent <LuaManager>(); if (mLuaManager == null) { mLuaManager = gameObject.AddComponent <LuaManager>(); } mKbeMain = gameObject.GetComponent <KBEMain>(); if (mKbeMain == null) { mKbeMain = gameObject.AddComponent <KBEMain>(); } OnInitialize(); }
private void BindLuaScript() { LuaManager luaMgr = FrameworkEntry.GetModule <LuaManager>(); LuaTable scriptEnv = luaMgr.luaEnv.NewTable(); LuaTable meta = luaMgr.luaEnv.NewTable(); meta.Set("__index", luaMgr.luaEnv.Global); scriptEnv.SetMetaTable(meta); meta.Dispose(); string luaFileName = string.Concat(UIName + "Logic"); string cmd = string.Concat("require 'ui/", luaFileName, "'"); luaMgr.luaEnv.DoString(cmd, luaFileName, scriptEnv); logicEnv = scriptEnv.Get <LuaTable>(UIName); //string bindMethodName = string.Concat(UIName, ".", BindMethod); //scriptEnv.GetInPath<Action<LuaTable, UIWnd>>(bindMethodName)?.Invoke(logicEnv, this); logicEnv.Get <Action <LuaTable, UIWnd> >(BindMethod)?.Invoke(logicEnv, this); }
public override void Trigger() { if (!Application.isPlaying) { return; } LuaManager luaMgr = AppFacade.Instance.GetManager <LuaManager>(); LuaFunction func = luaMgr.mainLua.GetFunction("EntityTextureNamePanel.show"); func.BeginPCall(); func.Push(ImageName); func.Push(Size); func.Push((int)Direction); func.PCall(); func.EndPCall(); }
public LuaCheckBox(LuaManager luaManager, string text, bool isChecked, double x, double y, double?width, double?height) { _luaManager = luaManager; CheckBox = new CheckBox { Content = text, IsChecked = isChecked }; if (width != null) { CheckBox.Width = width.Value; } if (height != null) { CheckBox.Height = height.Value; } CheckBox.Click += CheckBoxOnClick; }
public LuaTextBox(LuaManager luaManager, string text, double x, double y, double?width, double?height) { _luaManager = luaManager; TextBox = new TextBox { Text = text }; if (width != null) { TextBox.Width = width.Value; } if (height != null) { TextBox.Height = height.Value; } TextBox.TextChanged += TextBoxOnTextChanged; }
public LuaButton(LuaManager luaManager, string text, double x, double y, double?width, double?height) { _luaManager = luaManager; Button = new Button { Content = text }; if (width != null) { Button.Width = width.Value; } if (height != null) { Button.Height = height.Value; } Button.Click += ButtonOnClick; }
private void DoLuaFile() { if (luaFilePath.Length == 0) { EditorGUILayout.HelpBox("文件路径错误", MessageType.None); return; } if (!File.Exists(luaFilePath)) { EditorGUILayout.HelpBox("文件不存在", MessageType.None); return; } LuaManager mgr = AppFacade.Instance.GetManager <LuaManager>(ManagerName.Lua); mgr.DoFile(luaFilePath); }
public LuaComboBox(LuaManager luaManager, string value, List <string> values, double x, double y, double?width, double?height) { _luaManager = luaManager; ComboBox = new ComboBox { ItemsSource = new ObservableCollection <string>(values), SelectedItem = value }; if (width != null) { ComboBox.Width = (double)width; } if (height != null) { ComboBox.Height = (double)height; } ComboBox.SelectionChanged += ComboBoxOnSelectionChanged; }
/// <summary> /// 资源初始化结束 /// </summary> public void OnResourceInited() { //gameman添加main Component c = gameObject.GetComponent <Main>(); if (c == null) { gameObject.AddComponent <Main>(); } LuaManager.Start(); int start = Environment.TickCount; LuaManager.DoFile("Logic/Network"); //加载网络 LuaManager.DoFile("Logic/GameManager"); //加载游戏 initialize = true; //初始化完 NetManager.OnInit(); //初始化网络 //---------------------Lua面板--------------------------- object[] panels = CallMethod("LuaScriptPanel"); foreach (object o in panels) { string name = o.ToString().Trim(); if (string.IsNullOrEmpty(name)) { continue; } name += "Panel"; //添加 LuaManager.DoFile("View/" + name); Debug.LogWarning("LoadLua---->>>>" + name + ".lua"); } //------------------------------------------------------------ CallMethod("OnInitOK"); //初始化完成 int end = Environment.TickCount; UnityEngine.Debug.Log("tick" + (end - start)); }
static int getElementsByProperty(int L) { if (!LuaCommon.CheckAndShowArgsError(L, LConst.Table)) { return(0); } bool isTable = Lua.Lua_istable(L, -1); object page = LuaManager.GetLuaManager(L).DetailV_; if (isTable && page != null) { Dictionary <String, String> dic = new Dictionary <string, string>(); Lua.Lua_pushnil(L); while (Lua.Lua_next(L, -2) != 0) { String value = Lua.Lua_tostring(L, -1).ToString(); String key = Lua.Lua_tostring(L, -2).ToString(); dic[key] = value; Lua.Lua_pop(L, 1); } MethodInfo methods = page.GetType().GetMethod("getElementsByProperty"); Object[] pars = new Object[] { dic }; List <Object> temp = (List <Object>)methods.Invoke(page, pars); Lua.Lua_newtable(L); if (temp.Count == 0) { //string keyValue = dic[dic.Keys.GetEnumerator().Current]; //string message = string.Format("Control name='{0}' NOT found!", keyValue); //MessageBox.Show("getElementsByProperty return null"); //-return 0; Lua.Lua_rawset(L, -1); return(1); } for (int i = 0; i < temp.Count; i++) { Lua.Lua_pushnumber(L, i + 1); Lua.Lua_pushlightuserdata(L, temp[i]); Lua.LuaL_getmetatable(L, "elementFunction"); Lua.Lua_setmetatable(L, -2); Lua.Lua_rawset(L, -3); } } return(1); }
private static int get_Instance(LuaManager Instance,IntPtr l) { int id = LuaManager.Instance.PushStackObject(LuaManager.Instance); LuaApi.lua_pushnumber(l,id); return 1; }
static void Main(string[] args) { LuaManager lm = new LuaManager(); lm.Initialize(new Lua4NetRoot(), "Lua4NetRoot.lua", "application.lua", null); Console.ReadLine(); }
private static int Test(LuaManager Instance,IntPtr l) { // get method arguments LuaStackFunction lsf = new LuaStackFunction(3); LuaRefFunction lrf = new LuaRefFunction(4,l); // call method Instance.Test(lsf,lrf); return 0; }
private static int SetGlobalObject(LuaManager Instance,IntPtr l) { // get method arguments Int32 id = (Int32)LuaApi.lua_tonumber(l,3); int objId = (int)LuaApi.lua_tonumber(l,4); Object obj = LuaManager.Instance.GetObjectT<Object>(objId); // call method Instance.SetHeapObject(id,obj); return 0; }