static void CopyLuaBytesFiles(string sourceDir, string destDir, bool appendext = true, string searchPattern = "*.lua", SearchOption option = SearchOption.AllDirectories) { if (!Directory.Exists(sourceDir)) { return; } string[] files = Directory.GetFiles(sourceDir, searchPattern, option); int len = sourceDir.Length; if (sourceDir[len - 1] == '/' || sourceDir[len - 1] == '\\') { --len; } XLua.LuaEnv L = new XLua.LuaEnv(); for (int i = 0; i < files.Length; i++) { string str = files[i].Remove(0, len); string dest = destDir + "/" + str; if (appendext && !dest.EndsWith(".bytes")) { dest += ".bytes"; } string dir = Path.GetDirectoryName(dest); Directory.CreateDirectory(dir); CompileLuaFile(L, files[i], dest); //File.Copy(files[i], dest, true); } L.LuacClear(); L.GC(); L.Dispose(); }
// Start is called before the first frame update void Start() { //Debug.Log("Hello world!"); XLua.LuaEnv luaenv = new XLua.LuaEnv(); luaenv.DoString("CS.UnityEngine.Debug.Log('hello world')"); luaenv.Dispose(); }
public static void SaveString2() { TextAsset test = Resources.Load <TextAsset>("code/Skill001.lua"); XLua.LuaEnv luaenv = new XLua.LuaEnv(); //luaenv.DoString("CS.UnityEngine.Debug.Log('hello world')"); luaenv.DoString(test.text); luaenv.Dispose(); Debug.Log(test); return; CustomSkill skill = SkillUtils.MakeCustomSkill("001"); skill.id = 001; skill.Trigger(CustomSkill.TriggerType.fight); return; FormulaUtils.GetTowerExtraAttributes(false); return; for (int i = 0; i < 10; i++) { Debug.Log(UnityEngine.Random.Range(0, 0.5f)); } return; //PlayerSQLPrefs.yzTowerLevel = 10; //PlayerSQLPrefs.yzTowerABSLevel = 10; PlayerOtherItem.ReduceItem(GameInstance.GameDatabase.otherItem[0].Id, 10); }
private void Awake() { luaEnv = new XLua.LuaEnv(); scriptEnv = luaEnv.NewTable(); LuaTable meta = luaEnv.NewTable(); meta.Set("__index", luaEnv.Global); scriptEnv.SetMetaTable(meta); meta.Dispose(); scriptEnv.Set("mono", this); foreach (var injection in injections) { scriptEnv.Set(injection.name, injection.value); } luaEnv.DoString(luaScript.text, "LuaBehaviour", scriptEnv); Action luaAwake = scriptEnv.Get <Action>("awake"); scriptEnv.Get("start", out luaStart); scriptEnv.Get("update", out luaUpdate); scriptEnv.Get("fixedupdate", out luaFixedUpdate); scriptEnv.Get("ondestroy", out luaOnDestroy); if (luaAwake != null) { luaAwake(); } }
// Start is called before the first frame update void Start() { System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); XLua.LuaEnv luaenv = new XLua.LuaEnv(); var main = System.IO.File.ReadAllText(Application.dataPath + "\\main.lua"); luaenv.DoString(main); stopwatch.Start(); for (int i = 0; i < 1000; i++) { luaenv.DoString("StaticFunTest()"); } Debug.LogWarning($"耗時 {stopwatch.Elapsed}"); stopwatch.Restart(); for (int i = 0; i < 1000; i++) { luaenv.DoString("StaticFunTest2('123')"); } Debug.LogWarning($"耗時 {stopwatch.Elapsed}"); stopwatch.Restart(); for (int i = 0; i < 1000; i++) { luaenv.DoString("AddGenericList()"); } Debug.LogWarning($"耗時 {stopwatch.Elapsed}"); stopwatch.Restart(); luaenv.Dispose(); }
public static void SetMainLuaEnv(LuaState env) { if (LuaDeepProfilerSetting.Instance.isDeepProfiler) { if (env != null) { env.DoString(@" BeginMikuSample = CS.MikuLuaProfiler.LuaProfiler.BeginSample EndMikuSample = CS.MikuLuaProfiler.LuaProfiler.EndSample function miku_unpack_return_value(...) EndMikuSample() return ... end "); HookSetup.HookLuaFuns(); } } if (env == null) { HookSetup.Uninstall(); LuaProfiler.mainL = IntPtr.Zero; } }
private void init() { LuaEnv = new XLua.LuaEnv(); LuaEnv.AddLoader(FileUtils.LuaLoader); }
/// <summary> /// 初始化控制器 /// </summary> private void init() { mStatus = EnumConfig.SystemControllerStatusEnum.INIT; mLuaenv = new XLua.LuaEnv(); mLuaenv.DoString("CS.UnityEngine.Debug.Log('Lua Env create successful.')"); mScriptEnv = mLuaenv.NewTable(); Utils.BindMetaTable(mLuaenv, mScriptEnv); mScriptEnv.Set("self", this); foreach (var injection in injections) { mScriptEnv.Set(injection.name, injection.value); } mLuaenv.DoString(mLuaScript.text, "LuaTestScript", mScriptEnv); Action awake = mScriptEnv.Get <Action>("awake"); if (awake != null) { awake(); } mScriptEnv.Get("onStart", out mLuaStart); mScriptEnv.Get("update", out mLuaUpdate); mScriptEnv.Get("onDestroy", out mLuaOnDestroy); }
/// <summary> /// 销毁控制器 /// </summary> /// <returns>是否销毁成功</returns> public bool Destory() { if (mStatus == EnumConfig.SystemControllerStatusEnum.OVER) { Debug.LogError("system controller status is overed. destory faild."); return(false); } mStatus = EnumConfig.SystemControllerStatusEnum.OVER; if (mLuaOnDestroy != null) { mLuaOnDestroy(); } if (mLuaenv != null) { mLuaenv.Dispose(); } mLuaStart = null; mLuaUpdate = null; mLuaOnDestroy = null; mLuaenv = null; mScriptEnv.Dispose(); injections = null; return(true); }
static int _m_Dispose(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); XLua.LuaEnv gen_to_be_invoked = (XLua.LuaEnv)translator.FastGetCSObj(L, 1); int gen_param_count = LuaAPI.lua_gettop(L); if (gen_param_count == 1) { gen_to_be_invoked.Dispose( ); return(0); } if (gen_param_count == 2 && LuaTypes.LUA_TBOOLEAN == LuaAPI.lua_type(L, 2)) { bool _dispose = LuaAPI.lua_toboolean(L, 2); gen_to_be_invoked.Dispose(_dispose); return(0); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } return(LuaAPI.luaL_error(L, "invalid arguments to XLua.LuaEnv.Dispose!")); }
public MessageLua(XLua.LuaEnv luaEnv, UInt32 clsId, String clsName, UInt32 signId, String type, List <Attr> attrs) { _luaEnv = luaEnv; _luaTable = _luaEnv.NewTable(); _type = type; _luaTable.Set(s_sSelf, this); if (_type.Equals(s_sEnum)) { foreach (var v in attrs) { _luaTable.Set(v.name, Int32.Parse(v.defVal)); } } else { _clsId = clsId; _clsName = clsName; _signId = signId; _attrs = attrs; _luaTable.Set("ClsName", _clsName); _luaTable.Set("ClsId", _clsId); _luaTable.Set("SignId", _signId); _luaTable.Set <String, DelegateCreate>("Create", this.Create); } }
void Start() { luaEnv = new XLua.LuaEnv(); //luaEnv.DoString("print('hello world by execute string'"); luaEnv.DoString("require 'LuaScript.helloworld'"); }
private CLI.Result ExecuteByLine(CLI.Command cmd, int argFrom) { if (L == null) { L = new XLua.LuaEnv(); } return(LuaReturnToCLIResult(L.DoString(cmd.Raw))); }
public static void finalize() { s_messages.Clear(); s_lua_messages.Clear(); s_messages = null; s_lua_messages = null; s_luaEnv = null; }
private void OnDestroy() { if (luaEnv != null) { luaEnv.Dispose(); } luaEnv = null; }
/// <summary> /// 构造一个新的ModuleHub,对应一个模块 /// </summary> /// <param name="modName">模块的名字</param> /// <param name="parent">父模块,例如游戏模块的父模块是大厅模块</param> /// <param name="mountNode">视图节点,模块所有的view都挂在这个节点上</param> public ModuleHub(string modName, ModuleHub parent, MonoBehaviour monoBehaviour, XLua.LuaEnv luaenv) { this.modName = modName; this.parent = parent; this.luaenv = luaenv; this.monoBehaviour = monoBehaviour; // 选择模块的使用的加载器 SelectModuleLoader(); }
// Start is called before the first frame update void Start() { luaEnv = new XLua.LuaEnv(); luaEnv.AddLoader((ref string filepath) => { string path = PathDefines.luaDataPath + filepath + ".lua"; return(File.ReadAllBytes(path)); }); luaEnv.DoString(GameMainLua.text, "GameMainLua"); }
private void Start() { var env = new XLua.LuaEnv(); env.AddLoader(CustomLoad); env.DoString("print('this is CustomLoader'"); env.Dispose(); env = null; }
public void test() { Manager.Instance.RemoveAllDaemon(); ClearCommand(); ClearText(); L.GC(); L.Dispose(); L = new XLua.LuaEnv(); L.DoString("require ('Main')"); L.DoString("OnStart()"); }
static int _s_set_GcStepmul(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); XLua.LuaEnv gen_to_be_invoked = (XLua.LuaEnv)translator.FastGetCSObj(L, 1); gen_to_be_invoked.GcStepmul = LuaAPI.xlua_tointeger(L, 2); } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } return(0); }
static int _g_get_Memroy(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); XLua.LuaEnv gen_to_be_invoked = (XLua.LuaEnv)translator.FastGetCSObj(L, 1); LuaAPI.xlua_pushinteger(L, gen_to_be_invoked.Memroy); } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } return(1); }
public static void Load(String jsonPath, XLua.LuaEnv luaEnv) { try { if (!File.Exists(jsonPath)) { UnityEngine.Debug.LogError(String.Format("{0} no exists", jsonPath)); return; } StreamReader sr = File.OpenText(jsonPath); string input = sr.ReadToEnd(); var jsonObjects = MiniJSON.MiniJSON.jsonDecode(input) as ArrayList; foreach (Hashtable v in jsonObjects) { if (((String)v["type"]).Equals("Enum")) { var attrs = new List <MessageLua.Attr>(); foreach (Hashtable c in (ArrayList)v["attrs"]) { var attr = new MessageLua.Attr(); attr.name = (String)c["name"]; attr.defVal = (String)c["value"]; attrs.Add(attr); } var message = new MessageLua(luaEnv, 0, (String)v["clsName"], 0, (String)v["type"], attrs); App.SetTable((String)v["clsName"], message.GetLuaTable()); } else { var attrs = new List <MessageLua.Attr>(); foreach (Hashtable c in (ArrayList)v["attrs"]) { var attr = new MessageLua.Attr(); attr.name = (String)c["name"]; attr.type = (String)c["type"]; attr.defVal = (String)c["value"]; attrs.Add(attr); } var message = new MessageLua(luaEnv, (UInt32)(Double)v["clsId"], (String)v["clsName"], (UInt32)(Double)v["signId"], (String)v["type"], attrs); App.SetTable((String)v["clsName"], message.GetLuaTable()); App.RegisterMessage(message, true); } } } catch (Exception e) { UnityEngine.Debug.LogException(e); } }
static int _m_LoadString(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); XLua.LuaEnv gen_to_be_invoked = (XLua.LuaEnv)translator.FastGetCSObj(L, 1); int gen_param_count = LuaAPI.lua_gettop(L); if (gen_param_count == 4 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING) && (LuaAPI.lua_isnil(L, 3) || LuaAPI.lua_type(L, 3) == LuaTypes.LUA_TSTRING) && (LuaAPI.lua_isnil(L, 4) || LuaAPI.lua_type(L, 4) == LuaTypes.LUA_TTABLE)) { string _chunk = LuaAPI.lua_tostring(L, 2); string _chunkName = LuaAPI.lua_tostring(L, 3); XLua.LuaTable _env = (XLua.LuaTable)translator.GetObject(L, 4, typeof(XLua.LuaTable)); XLua.LuaFunction gen_ret = gen_to_be_invoked.LoadString(_chunk, _chunkName, _env); translator.Push(L, gen_ret); return(1); } if (gen_param_count == 3 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING) && (LuaAPI.lua_isnil(L, 3) || LuaAPI.lua_type(L, 3) == LuaTypes.LUA_TSTRING)) { string _chunk = LuaAPI.lua_tostring(L, 2); string _chunkName = LuaAPI.lua_tostring(L, 3); XLua.LuaFunction gen_ret = gen_to_be_invoked.LoadString(_chunk, _chunkName); translator.Push(L, gen_ret); return(1); } if (gen_param_count == 2 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING)) { string _chunk = LuaAPI.lua_tostring(L, 2); XLua.LuaFunction gen_ret = gen_to_be_invoked.LoadString(_chunk); 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 XLua.LuaEnv.LoadString!")); }
public static void initialize(XLua.LuaEnv luaEnv = null) { try { s_workPath = System.IO.Path.Combine(Application.persistentDataPath, "FastNet"); if (Directory.Exists(s_workPath) == false) { Directory.CreateDirectory(s_workPath); } s_luaEnv = luaEnv; var types = Assembly.GetAssembly(typeof(App)).GetTypes(); foreach (var type in types) { try { var baseType = type.BaseType; if (baseType != null) { if ("FastNet.Cfg`2".Equals(baseType.Namespace + "." + baseType.Name)) { var method = type.GetMethod("Init", BindingFlags.Public | BindingFlags.Static); method.Invoke(null, null); } else if ("FastNet.Message".Equals(baseType.Namespace + "." + baseType.Name)) { RegisterMessage(type, false); } } } catch (Exception e) { UnityEngine.Debug.LogException(e); } } if (luaEnv != null) { //pkt MessageLua.Load(s_workPath + "/pkt_table.bytes", luaEnv); //cfg CfgLua.Load(s_workPath + "/cfg_table.bytes", luaEnv); } } catch (Exception e) { Debug.LogException(e); } }
public static void Load(String jsonPath, XLua.LuaEnv luaEnv) { try { if (!File.Exists(jsonPath)) { UnityEngine.Debug.LogError(String.Format("{0} no exists", jsonPath)); return; } StreamReader sr = File.OpenText(jsonPath); string input = sr.ReadToEnd(); var jsonObjects = MiniJSON.MiniJSON.jsonDecode(input) as ArrayList; foreach (Hashtable v in jsonObjects) { var attrs = new List <CfgLua.Attr>(); foreach (Hashtable c in (ArrayList)v["attrs"]) { var attr = new CfgLua.Attr(); attr.name = (String)c["name"]; attr.type = (String)c["type"]; attr.defVal = (String)c["value"]; attrs.Add(attr); } var ttt = v["clsId"].GetType(); var clsId = (Double)v["clsId"]; var signId = (Double)v["signId"]; var message = new CfgLua(luaEnv, (UInt32)clsId, (String)v["clsName"], (UInt32)signId, attrs, (String)v["index"], (String)v["cfgPath"]); App.SetTable((String)v["clsName"], message); } foreach (Hashtable v in jsonObjects) { var cl = luaEnv.Global.GetInPath <CfgLua>((String)v["clsName"]); cl.LoadCfg(); } } catch (Exception e) { UnityEngine.Debug.LogException(e); } }
protected LuaModule() { #if UNITY_EDITOR UnityEngine.Debug.Log("Consturct LuaModule..."); #endif #if SLUA _luaSvr = new LuaSvr(); _luaSvr.init(progress => { _initProgress = progress; }, () => { }); #else _luaEnv = new LuaEnv(); #endif }
private XLua.LuaEnv CreateLuaEnv() { XLua.LuaEnv luaEnv = new XLua.LuaEnv(); /* * luaEnv.AddBuildin("rapidjson", XLua.LuaDLL.Lua.LoadRapidJson); * luaEnv.AddBuildin("lpeg", XLua.LuaDLL.Lua.LoadLpeg); * luaEnv.AddBuildin("pb", XLua.LuaDLL.Lua.LoadLuaProfobuf); * luaEnv.AddBuildin("ffi", XLua.LuaDLL.Lua.LoadFFI); */ luaEnv.AddLoader(this.LoadLuaScript); return(luaEnv); }
void Start() { luaEnv = new XLua.LuaEnv(); luaEnv.DoString("CS.UnityEngine.Debug.Log('Hello Wold')"); var max = luaEnv.Global.GetInPath <LuaArgs>("math.max"); var min = luaEnv.Global.GetInPath <LuaArgs>("math.min"); var random = luaEnv.Global.GetInPath <LuaArgs>("math.random"); Debug.Log("max:" + max(32, 12)); Debug.Log("min:" + min(32, 12)); Debug.Log("random:" + random(1, 10)); }
// Use this for initialization void Start() { if (Instance == null) { Destroy(Instance); } Instance = this; if (L == null) { L = new XLua.LuaEnv(); L.DoString("require ('Main')"); L.DoString("OnStart()"); } }
private CLI.Result ExecuteWithFile(CLI.Command cmd, int argFrom) { var www = new WWW(FileServerDomain + cmd[0]); while (!www.isDone) { ; } if (L == null) { L = new XLua.LuaEnv(); } return(LuaReturnToCLIResult(L.DoString(www.text))); }