// Use this for initialization void Start() { LuaEnv luaenv = new LuaEnv(); luaenv.DoString(script); CalcNew calc_new = luaenv.Global.GetInPath<CalcNew>("Calc.New"); ICalc calc = calc_new(10, "hi", "john"); //constructor Debug.Log("sum(*10) =" + calc.Add(1, 2)); calc.Mult = 100; Debug.Log("sum(*100)=" + calc.Add(1, 2)); luaenv.Dispose(); }
// Use this for initialization void Start() { luaenv = new LuaEnv(); luaenv.AddLoader((ref string filename) => { if (filename == "InMemory") { string script = "return {ccc = 9999}"; return System.Text.Encoding.UTF8.GetBytes(script); } return null; }); luaenv.DoString("print('InMemory.ccc=', require('InMemory').ccc)"); }
public static IEnumerable<CustomGenTask> GetTasks(LuaEnv lua_env, UserConfig user_cfg) { LuaTable data = lua_env.NewTable(); var assembly_infos = (from type in user_cfg.ReflectionUse group type by type.Assembly.GetName().Name into assembly_info select new { FullName = assembly_info.Key, Types = assembly_info.ToList()}).ToList(); data.Set("assembly_infos", assembly_infos); yield return new CustomGenTask { Data = data, Output = new StreamWriter(GeneratorConfig.common_path + "/link.xml", false, Encoding.UTF8) }; }
static void wrapInit0(LuaEnv luaenv, ObjectTranslator translator) { translator.DelayWrapLoader(typeof(XLuaManager), XLuaManagerWrap.__Register); translator.DelayWrapLoader(typeof(XLuaFramework.AppConfig), XLuaFrameworkAppConfigWrap.__Register); translator.DelayWrapLoader(typeof(XLuaFramework.CookiesManager), XLuaFrameworkCookiesManagerWrap.__Register); translator.DelayWrapLoader(typeof(XLuaFramework.NetPackageType), XLuaFrameworkNetPackageTypeWrap.__Register); translator.DelayWrapLoader(typeof(XLuaFramework.NetworkManager), XLuaFrameworkNetworkManagerWrap.__Register); translator.DelayWrapLoader(typeof(XLuaFramework.ResourceManager), XLuaFrameworkResourceManagerWrap.__Register); translator.DelayWrapLoader(typeof(XLuaFramework.UIHelper), XLuaFrameworkUIHelperWrap.__Register); translator.DelayWrapLoader(typeof(XLuaFramework.Util), XLuaFrameworkUtilWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.GameVariable), UnityMMOGameVariableWrap.__Register); translator.DelayWrapLoader(typeof(object), SystemObjectWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Object), UnityEngineObjectWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Vector2), UnityEngineVector2Wrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Vector3), UnityEngineVector3Wrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Vector4), UnityEngineVector4Wrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Quaternion), UnityEngineQuaternionWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Color), UnityEngineColorWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Ray), UnityEngineRayWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Bounds), UnityEngineBoundsWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Ray2D), UnityEngineRay2DWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Time), UnityEngineTimeWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.GameObject), UnityEngineGameObjectWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Component), UnityEngineComponentWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Behaviour), UnityEngineBehaviourWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Transform), UnityEngineTransformWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Resources), UnityEngineResourcesWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.TextAsset), UnityEngineTextAssetWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Keyframe), UnityEngineKeyframeWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.AnimationCurve), UnityEngineAnimationCurveWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.AnimationClip), UnityEngineAnimationClipWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.MonoBehaviour), UnityEngineMonoBehaviourWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.ParticleSystem), UnityEngineParticleSystemWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.SkinnedMeshRenderer), UnityEngineSkinnedMeshRendererWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Renderer), UnityEngineRendererWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Light), UnityEngineLightWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Mathf), UnityEngineMathfWrap.__Register); translator.DelayWrapLoader(typeof(System.Collections.Generic.List <int>), SystemCollectionsGenericList_1_SystemInt32_Wrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.UI.InputField), UnityEngineUIInputFieldWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.TextAnchor), UnityEngineTextAnchorWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.RaycastHit), UnityEngineRaycastHitWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Touch), UnityEngineTouchWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.TouchPhase), UnityEngineTouchPhaseWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.LayerMask), UnityEngineLayerMaskWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Plane), UnityEnginePlaneWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.RectTransform), UnityEngineRectTransformWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.TextMesh), UnityEngineTextMeshWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.UI.Graphic), UnityEngineUIGraphicWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.EventSystems.UIBehaviour), UnityEngineEventSystemsUIBehaviourWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.UI.MaskableGraphic), UnityEngineUIMaskableGraphicWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.UI.MaskableGraphic.CullStateChangedEvent), UnityEngineUIMaskableGraphicCullStateChangedEventWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.UI.ScrollRect), UnityEngineUIScrollRectWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.UI.ScrollRect.MovementType), UnityEngineUIScrollRectMovementTypeWrap.__Register); }
void OnDestroy() { env = null; luaManager = null; }
static void wrapInit0(LuaEnv luaenv, ObjectTranslator translator) { translator.DelayWrapLoader(typeof(LuaBehaviour), LuaBehaviourWrap.__Register); translator.DelayWrapLoader(typeof(XLuaTest.Pedding), XLuaTestPeddingWrap.__Register); translator.DelayWrapLoader(typeof(XLuaTest.MyStruct), XLuaTestMyStructWrap.__Register); translator.DelayWrapLoader(typeof(XLuaTest.MyEnum), XLuaTestMyEnumWrap.__Register); translator.DelayWrapLoader(typeof(XLuaTest.NoGc), XLuaTestNoGcWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.WaitForSeconds), UnityEngineWaitForSecondsWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.WWW), UnityEngineWWWWrap.__Register); translator.DelayWrapLoader(typeof(BaseTest), BaseTestWrap.__Register); translator.DelayWrapLoader(typeof(Foo1Parent), Foo1ParentWrap.__Register); translator.DelayWrapLoader(typeof(Foo2Parent), Foo2ParentWrap.__Register); translator.DelayWrapLoader(typeof(Foo1Child), Foo1ChildWrap.__Register); translator.DelayWrapLoader(typeof(Foo2Child), Foo2ChildWrap.__Register); translator.DelayWrapLoader(typeof(Foo), FooWrap.__Register); translator.DelayWrapLoader(typeof(FooExtension), FooExtensionWrap.__Register); translator.DelayWrapLoader(typeof(object), SystemObjectWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Object), UnityEngineObjectWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Vector2), UnityEngineVector2Wrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Vector3), UnityEngineVector3Wrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Vector4), UnityEngineVector4Wrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Quaternion), UnityEngineQuaternionWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Color), UnityEngineColorWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Ray), UnityEngineRayWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Bounds), UnityEngineBoundsWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Ray2D), UnityEngineRay2DWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Time), UnityEngineTimeWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.GameObject), UnityEngineGameObjectWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Component), UnityEngineComponentWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Behaviour), UnityEngineBehaviourWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Transform), UnityEngineTransformWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Resources), UnityEngineResourcesWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.TextAsset), UnityEngineTextAssetWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Keyframe), UnityEngineKeyframeWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.AnimationCurve), UnityEngineAnimationCurveWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.AnimationClip), UnityEngineAnimationClipWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.MonoBehaviour), UnityEngineMonoBehaviourWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.ParticleSystem), UnityEngineParticleSystemWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.SkinnedMeshRenderer), UnityEngineSkinnedMeshRendererWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Renderer), UnityEngineRendererWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Light), UnityEngineLightWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Mathf), UnityEngineMathfWrap.__Register); translator.DelayWrapLoader(typeof(System.Collections.Generic.List <int>), SystemCollectionsGenericList_1_SystemInt32_Wrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Debug), UnityEngineDebugWrap.__Register); translator.DelayWrapLoader(typeof(Tutorial.BaseClass), TutorialBaseClassWrap.__Register); translator.DelayWrapLoader(typeof(Tutorial.TestEnum), TutorialTestEnumWrap.__Register); translator.DelayWrapLoader(typeof(Tutorial.PrivateOverrideClass), TutorialPrivateOverrideClassWrap.__Register); translator.DelayWrapLoader(typeof(Tutorial.DerivedClass), TutorialDerivedClassWrap.__Register); translator.DelayWrapLoader(typeof(Tutorial.DerivedClass.TestEnumInner), TutorialDerivedClassTestEnumInnerWrap.__Register); translator.DelayWrapLoader(typeof(Tutorial.ICalc), TutorialICalcWrap.__Register); translator.DelayWrapLoader(typeof(Tutorial.DerivedClassExtensions), TutorialDerivedClassExtensionsWrap.__Register); }
public TutorialCSCallLuaItfDBridge(int reference, LuaEnv luaenv) : base(reference, luaenv) { }
// Use this for initialization void Start() { luaenv = new LuaEnv(); luaenv.DoString("require 'coruntine_test'"); }
public DelegateBridge(int reference, LuaEnv luaenv) : base(reference, luaenv) { }
private void Awake() { luaEnv = new LuaEnv(); luaEnv.AddLoader(CustomLoader); Instance = this; }
// Use this for initialization void Start() { luaenv = new LuaEnv(); luaenv.DoString("print('hello world')"); }
public virtual void Dispose(bool disposeManagedResources) { if (!disposed) { if (luaReference != 0) { #if THREAD_SAFT || HOTFIX_ENABLE lock (luaEnv.luaEnvLock) { #endif bool is_delegate = this is DelegateBridgeBase; if (disposeManagedResources) { luaEnv.translator.ReleaseLuaBase(luaEnv.L, luaReference, is_delegate); } else //will dispse by LuaEnv.GC { luaEnv.equeueGCAction(new LuaEnv.GCAction { Reference = luaReference, IsDelegate = is_delegate }); } #if THREAD_SAFT || HOTFIX_ENABLE } #endif } luaEnv = null; disposed = true; } }
public LuaBase(int reference, LuaEnv luaenv) { luaReference = reference; luaEnv = luaenv; }
private void Start() { env = new LuaEnv(); env.DoString(script); }
// Use this for initialization void Start() { luaenv = new LuaEnv(); luaenv.DoString("require 'byfile'"); }
// Use this for initialization void Start() { LuaEnv luaenv = new LuaEnv(); luaenv.DoString("CS.UnityEngine.Debug.Log('hello world')"); luaenv.Dispose(); }
// 销毁Lua public override void Dispose() { luaEnv.Dispose(); luaEnv = null; base.Dispose(); }
public MariaLuaILuaClientSockBridge(int reference, LuaEnv luaenv) : base(reference, luaenv) { }
public LuaString(int reference, LuaEnv luaenv, string value, IntPtr strPoint) : base(reference, luaenv) { this.value = value; this.strPoint = strPoint; }
// Use this for initialization void Start() { LuaEnv luaenv = new LuaEnv(); HotfixCalc calc = new HotfixCalc(); NoHotfixCalc ordinaryCalc = new NoHotfixCalc(); int CALL_TIME = 100 * 1000 * 1000; var start = System.DateTime.Now; for (int i = 0; i < CALL_TIME; i++) { calc.Add(2, 1); } var d1 = (System.DateTime.Now - start).TotalMilliseconds; Debug.Log("Hotfix using:" + d1); start = System.DateTime.Now; for (int i = 0; i < CALL_TIME; i++) { ordinaryCalc.Add(2, 1); } var d2 = (System.DateTime.Now - start).TotalMilliseconds; Debug.Log("No Hotfix using:" + d2); Debug.Log("drop:" + ((d1 - d2) / d1)); Debug.Log("Before Fix: 2 + 1 = " + calc.Add(2, 1)); Debug.Log("Before Fix: Vector3(2, 3, 4) + Vector3(1, 2, 3) = " + calc.Add(new Vector3(2, 3, 4), new Vector3(1, 2, 3))); luaenv.DoString(@" xlua.hotfix(CS.XLuaTest.HotfixCalc, 'Add', function(self, a, b) return a + b end) "); Debug.Log("After Fix: 2 + 1 = " + calc.Add(2, 1)); Debug.Log("After Fix: Vector3(2, 3, 4) + Vector3(1, 2, 3) = " + calc.Add(new Vector3(2, 3, 4), new Vector3(1, 2, 3))); double num; string str = "hehe"; int ret = calc.TestOut(100, out num, ref str); Debug.Log("ret = " + ret + ", num = " + num + ", str = " + str); luaenv.DoString(@" xlua.hotfix(CS.XLuaTest.HotfixCalc, 'TestOut', function(self, a, c, go) print('TestOut', self, a, c, go) if go then error('test error') end return a + 10, a + 20, 'right version' end) "); str = "hehe"; ret = calc.TestOut(100, out num, ref str); Debug.Log("ret = " + ret + ", num = " + num + ", str = " + str); luaenv.DoString(@" xlua.hotfix(CS.XLuaTest.HotfixCalc, { Test1 = function(self) print('Test1', self) return 1 end; Test2 = function(self, a, b) print('Test1', self, a, b) return a + 10, 1024, b end; Test3 = function(a) print(a) return 10 end; Test4 = function(a) print(a) end; Test5 = function(self, a, ...) print('Test4', self, a, ...) end }) "); int r1 = calc.Test1 <int>(); double r2 = calc.Test1 <double>(); Debug.Log("r1:" + r1 + ",r2:" + r2); string ss = "heihei"; int r3 = calc.Test2(r1, out r2, ref ss); Debug.Log("r1:" + r1 + ",r2:" + r2 + ",r3:" + r3 + ",ss:" + ss); r3 = HotfixCalc.Test3("test3"); r3 = HotfixCalc.Test3(2); r3 = HotfixCalc.Test3(this); Debug.Log("r3:" + r3); HotfixCalc.Test4(this); HotfixCalc.Test4(2); calc.Test5(10, "a", "b", "c"); calc.Test5(10, 1, 3, 5); Debug.Log("----------------------before------------------------"); TestStateful(); System.GC.Collect(); System.GC.WaitForPendingFinalizers(); luaenv.DoString(@" local util = require 'xlua.util' xlua.hotfix(CS.XLuaTest.StatefullTest, { ['.ctor'] = function(csobj) util.state(csobj, {evt = {}, start = 0, prop = 0}) end; set_AProp = function(self, v) print('set_AProp', v) self.prop = v end; get_AProp = function(self) return self.prop end; get_Item = function(self, k) print('get_Item', k) return 1024 end; set_Item = function(self, k, v) print('set_Item', k, v) end; add_AEvent = function(self, cb) print('add_AEvent', cb) table.insert(self.evt, cb) end; remove_AEvent = function(self, cb) print('remove_AEvent', cb) for i, v in ipairs(self.evt) do if v == cb then table.remove(self.evt, i) break end end end; Start = function(self) print('Start') for _, cb in ipairs(self.evt) do cb(self.start, 2) end self.start = self.start + 1 end; StaticFunc = function(a, b, c) print(a, b, c) end; GenericTest = function(self, a) print(self, a) end; Finalize = function(self) print('Finalize', self) end }) "); Debug.Log("----------------------after------------------------"); TestStateful(); luaenv.FullGc(); System.GC.Collect(); System.GC.WaitForPendingFinalizers(); Debug.LogError("_________________________________"); var genericObj = new GenericClass <double>(1.1); genericObj.Func1(); Debug.Log(genericObj.Func2()); luaenv.DoString(@" xlua.hotfix(CS.XLuaTest.GenericClass(CS.System.Double), { ['.ctor'] = function(obj, a) print('GenericClass<double>', obj, a) end; Func1 = function(obj) print('GenericClass<double>.Func1', obj) end; Func2 = function(obj) print('GenericClass<double>.Func2', obj) return 1314 end }) "); genericObj = new GenericClass <double>(1.1); genericObj.Func1(); Debug.Log(genericObj.Func2()); InnerTypeTest itt = new InnerTypeTest(); itt.Foo(); luaenv.DoString(@" xlua.hotfix(CS.XLuaTest.InnerTypeTest, 'Bar', function(obj) print('lua Bar', obj) return {x = 10, y = 20} end) "); itt.Foo(); StructTest st = new StructTest(gameObject); Debug.Log("go=" + st.GetGo(123, "john")); luaenv.DoString(@" xlua.hotfix(CS.XLuaTest.StructTest, 'GetGo', function(self, a, b) print('GetGo', self, a, b) return nil end) "); Debug.Log("go=" + st.GetGo(123, "john")); GenericStruct <int> gs = new GenericStruct <int>(1); Debug.Log("gs.GetA()=" + gs.GetA(123)); luaenv.DoString(@" xlua.hotfix(CS.XLuaTest.GenericStruct(CS.System.Int32), 'GetA', function(self, a) print('GetA',self, a) return 789 end) "); Debug.Log("gs.GetA()=" + gs.GetA(123)); try { calc.TestOut(100, out num, ref str, gameObject); } catch (LuaException e) { Debug.Log("throw in lua an catch in c# ok, e.Message:" + e.Message); } BaseTestBase <InnerTypeTest> bt = new BaseTest(); bt.Foo(1); Debug.Log(bt); luaenv.DoString(@" xlua.hotfix(CS.XLuaTest.BaseTest, 'Foo', function(self, p) print('BaseTest', p) end) xlua.hotfix(CS.XLuaTest.BaseTest, 'ToString', function(self) return '>>>' .. base(self):ToString() end) "); bt.Foo(2); Debug.Log(bt); }
public static void SetMainLuaEnv(LuaEnv env) { _mainEnv = env; }
public static LuaFunction Compile(LuaEnv luaenv, string snippet) { return luaenv.LoadString(ComposeCode(Parser.Parse(snippet)), "luatemplate"); }
void Start() { luaenv = new LuaEnv(); luaenv.DoString("require 'async_test'"); }
public static void ProxySearcher(LuaEnv env, LuaCSFunction searcher, int index) { }
// Start is called before the first frame update void Start() { luaEnv = new LuaEnv(); luaEnv.DoString(luaScript.text); }
public static LuaBase __Create(int reference, LuaEnv luaenv) { return(new TutorialCSCallLuaItfDBridge(reference, luaenv)); }
public void resetMainLua() { _mainLua = new LuaEnv(); }
public XLuaManager() { luaEnv = new LuaEnv(); LuaEnv.CustomLoader loader = OriginalLuaLoader; luaEnv.AddLoader(loader); }
void Start() { luaenv = new LuaEnvEx(); }
IEnumerator CopyToPersistentDataPath() { string dataPath = Application.persistentDataPath; //Util.DataPath; //数据目录 string resPath = PathTools.AppContentPath(); //Util.AppContentPath(); //游戏包资源目录 if (Directory.Exists(dataPath)) { Directory.Delete(dataPath, true); } Directory.CreateDirectory(dataPath); string infile = resPath + "md5filelist.txt"; string outfile = dataPath + "md5filelist.txt"; if (File.Exists(outfile)) { File.Delete(outfile); } string message = "正在解包文件:>files.txt"; Debug.Log(infile); Debug.Log(outfile); if (Application.platform == RuntimePlatform.Android) { WWW www = new WWW(infile); while (true) { if (www.isDone || !string.IsNullOrEmpty(www.error)) { System.Threading.Thread.Sleep(50); if (!string.IsNullOrEmpty(www.error)) { Debug.LogError(www.error); } else { File.WriteAllBytes(outfile, www.bytes); } break; } } yield return(0); } else { File.Copy(infile, outfile, true); } yield return(new WaitForEndOfFrame()); //释放所有文件到数据目录 string[] files = File.ReadAllLines(outfile); foreach (var file in files) { string[] fs = file.Split('='); if (fs.Length == 1) { Debug.LogWarning("跳过 >>" + file); continue; } if (resPath.EndsWith("/") && fs [0].StartsWith("/")) { resPath = resPath.Substring(0, resPath.Length - 1); } if (dataPath.EndsWith("/") && fs [0].StartsWith("/")) { dataPath = dataPath.Substring(0, dataPath.Length - 1); } infile = resPath + fs[0]; // outfile = dataPath + fs[0]; message = "正在解包文件:>" + fs[0]; Debug.Log("正在解包文件:>" + infile); string dir = Path.GetDirectoryName(outfile); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } if (Application.platform == RuntimePlatform.Android) { WWW www = new WWW(infile); while (true) { if (www.isDone || !string.IsNullOrEmpty(www.error)) { System.Threading.Thread.Sleep(50); if (!string.IsNullOrEmpty(www.error)) { Debug.LogError(www.error); } else { File.WriteAllBytes(outfile, www.bytes); Debug.LogWarning(">>" + outfile + ">>" + www.bytes.Length); } break; } } /* * yield return www; * * if (www.isDone) { * File.WriteAllBytes(outfile, www.bytes); * Debug.LogWarning (">>" + outfile+">>"+www.bytes.Length); * } */ yield return(0); } else { if (File.Exists(outfile)) { File.Delete(outfile); } File.Copy(infile, outfile, true); } yield return(new WaitForEndOfFrame()); } message = "解包完成!!!"; luaManager = LuaManager.GetInstance(); luaManager.InitDoString = "require 'lua/game/GameState' \n game_state_init() \n"; env = luaManager.LuaEnvGetOrNew(); yield return(new WaitForSeconds(1f)); RunState(); isCopyCmp = true; }
void Start() { luaEnv = new LuaEnv(); //初始化LuaEnv模块 luaEnv.AddLoader(Myloader); //添加lua存放文件夹 luaEnv.DoString("require 'Fish'"); //配合luaEnv.AddLoader(Myloader)添加名为 Fish 的lua文件,并执行该lua文件内容(调用Fish.lua) }
static void wrapInit1(LuaEnv luaenv, ObjectTranslator translator) { translator.DelayWrapLoader(typeof(UnityEngine.UI.ScrollRect.ScrollbarVisibility), UnityEngineUIScrollRectScrollbarVisibilityWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.UI.Image), UnityEngineUIImageWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.UI.Image.Type), UnityEngineUIImageTypeWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.UI.Image.FillMethod), UnityEngineUIImageFillMethodWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.UI.Image.OriginHorizontal), UnityEngineUIImageOriginHorizontalWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.UI.Image.OriginVertical), UnityEngineUIImageOriginVerticalWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.UI.Image.Origin90), UnityEngineUIImageOrigin90Wrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.UI.Image.Origin180), UnityEngineUIImageOrigin180Wrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.UI.Image.Origin360), UnityEngineUIImageOrigin360Wrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Animator), UnityEngineAnimatorWrap.__Register); translator.DelayWrapLoader(typeof(CircleRawImage), CircleRawImageWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.UI.RawImage), UnityEngineUIRawImageWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Camera), UnityEngineCameraWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Physics), UnityEnginePhysicsWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Input), UnityEngineInputWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.KeyCode), UnityEngineKeyCodeWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.RenderTexture), UnityEngineRenderTextureWrap.__Register); translator.DelayWrapLoader(typeof(Cinemachine.CinemachineFreeLook), CinemachineCinemachineFreeLookWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.UI.ScrollRect.ScrollRectEvent), UnityEngineUIScrollRectScrollRectEventWrap.__Register); translator.DelayWrapLoader(typeof(UnityEngine.Debug), UnityEngineDebugWrap.__Register); translator.DelayWrapLoader(typeof(Unity.Entities.World), UnityEntitiesWorldWrap.__Register); translator.DelayWrapLoader(typeof(Unity.Entities.Entity), UnityEntitiesEntityWrap.__Register); translator.DelayWrapLoader(typeof(Unity.Entities.GameObjectEntity), UnityEntitiesGameObjectEntityWrap.__Register); translator.DelayWrapLoader(typeof(Unity.Entities.EntityManagerExtensions), UnityEntitiesEntityManagerExtensionsWrap.__Register); translator.DelayWrapLoader(typeof(Unity.Entities.EntityManager), UnityEntitiesEntityManagerWrap.__Register); translator.DelayWrapLoader(typeof(TMPro.TextMeshProUGUI), TMProTextMeshProUGUIWrap.__Register); translator.DelayWrapLoader(typeof(TMPro.TMP_InputField), TMProTMP_InputFieldWrap.__Register); translator.DelayWrapLoader(typeof(TMPro.TMP_Text), TMProTMP_TextWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.UID), UnityMMOUIDWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.UIDProxy), UnityMMOUIDProxyWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.GameConst), UnityMMOGameConstWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.ResPath), UnityMMOResPathWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.ECSHelper), UnityMMOECSHelperWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.GameInput), UnityMMOGameInputWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.MainWorld), UnityMMOMainWorldWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.AutoFight), UnityMMOAutoFightWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.MonsterMgr), UnityMMOMonsterMgrWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.NPCMgr), UnityMMONPCMgrWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.RoleInfo), UnityMMORoleInfoWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.RoleMgr), UnityMMORoleMgrWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.RoleLooksInfo), UnityMMORoleLooksInfoWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.ResMgr), UnityMMOResMgrWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.BornInfo), UnityMMOBornInfoWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.BornInfoData), UnityMMOBornInfoDataWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.RaycastSceneObjHit), UnityMMORaycastSceneObjHitWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.SceneHelper), UnityMMOSceneHelperWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.SceneInfo), UnityMMOSceneInfoWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.BaseSceneInfoData), UnityMMOBaseSceneInfoDataWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.SceneInfoKey), UnityMMOSceneInfoKeyWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.SceneObjectType), UnityMMOSceneObjectTypeWrap.__Register); translator.DelayWrapLoader(typeof(UnityMMO.SceneMgr), UnityMMOSceneMgrWrap.__Register); }
public static LuaFunction Compile(LuaEnv luaenv, string snippet) { return(luaenv.LoadString <LuaFunction>(ComposeCode(Parser.Parse(snippet)), "luatemplate")); }
public virtual void Init() { if (scriptEnv != null) { return; } if (string.IsNullOrEmpty(luaPath)) { luaFilePathDic.TryGetValue(gameObject, out luaPath); luaFilePathDic.Remove(gameObject); } if (string.IsNullOrEmpty(luaPath)) { Debug.LogError(" luaPath = null !"); return; } if (!luaPath.Trim().EndsWith(".lua")) { luaPath = luaPath + ".lua"; } string luaCode; string filePath; byte[] code = null; #if UNITY_EDITOR /* 在编辑器下从 Resources 下加载 */ filePath = Application.dataPath + "/Resources/" + luaPath; code = System.IO.File.ReadAllBytes(filePath); Debug.LogWarningFormat("LuaBaseBehaviour load file {0}", filePath); #else //filePath = Application.persistentDataPath + "/" + luaPath; code = ReadRes.ReadByte(luaPath); #endif if (code == null) { Debug.LogError("lua code is null " + luaPath); return; } luaEnv = LuaManager.GetInstance().LuaEnvGetOrNew(); scriptEnv = luaEnv.NewTable(); LuaTable meta = luaEnv.NewTable(); meta.Set("__index", luaEnv.Global); scriptEnv.SetMetaTable(meta); meta.Dispose(); scriptEnv.Set("self", this); scriptEnv.Set("scriptEnv", scriptEnv); if (injections != null) { foreach (var injection in injections) { scriptEnv.Set(injection.name, injection.value); } } scriptEnv.Set("luaPath", luaPath); luaEnv.DoString(code, "LuaBaseBehaviour", scriptEnv); //luaEnv.DoString(string.Format("require '{0}'",luaPath), "LuaBaseBehaviour_"+gameObject.GetInstanceID(), scriptEnv); //luaEnv.DoString("function awake()\n\nend\t\n\nfunction start()\n\tprint(\"LuaBaseBehaviour start...\"..self.luaPath)\nend\n\nfunction update()\n\tlocal r = CS.UnityEngine.Vector3.up * CS.UnityEngine.Time.deltaTime\n\tself.transform:Rotate(r)\nend\n\nfunction ondestroy()\n print(\"LuaBaseBehaviour destroy...\"..self.luaPath)\nend", "LuaBaseBehaviour", scriptEnv); scriptEnv.Get("awake", out luaAwake); /* * if (luaAwake == null) { * Debug.LogError ("awake null"); * } else { * Debug.LogError ("awake "); * } */ //#if UNITY_EDITOR if (luaAwake != null && !luaAwakeInited) { luaAwake(); luaAwakeInited = true; } //#endif scriptEnv.Get("start", out luaStart); //scriptEnv.Get("update", out luaUpdate); scriptEnv.Get("ondestroy", out luaOnDestroy); }
static void Init(LuaEnv luaenv, ObjectTranslator translator) { wrapInit0(luaenv, translator); }
public static LuaBase __Create(int reference, LuaEnv luaenv) { return(new MariaLuaILuaClientSockBridge(reference, luaenv)); }
public MariaLuaILuaContextBridge(int reference, LuaEnv luaenv) : base(reference, luaenv) { }
public void Register(LuaEnv xL) { _instance = this; }
/// <summary> /// Dispose xLua environment /// </summary> public static void Release() { Env?.Dispose(); Env = null; }
private void Awake() { _luaEnv = new LuaEnv(); }
// Start is called before the first frame update void Start() { luaEnv = new LuaEnv(); luaEnv.AddLoader(loader); luaEnv.DoString("require 'Test3/Test3Main'"); }
public static void Main() { LuaEnv luaenv = new LuaEnv(); luaenv.DoString("CS.System.Console.WriteLine('hello world')"); var max = luaenv.Global.GetInPath <LuaMax>("math.max"); Console.WriteLine("max:" + max(32, 12)); luaenv.Global.Set("obj1", new AccessByGenGode()); luaenv.Global.Set("obj2", new AccessByReflection()); luaenv.DoString(@" local p = CS.Point(3, 4) print('-----------------------------') obj2:Print(p) print('-----------------------------') obj1:Print(p) print('-----------------------------') "); var calc = new Calc(); luaenv.Global.Set("calc", calc); luaenv.DoString("print(calc:Add(2, 4))"); try { Console.WriteLine("2 + 4 =" + calc.Add(2, 4)); luaenv.DoString(@" xlua.hotfix(CS.Calc, 'Add', function(self, a, b) return a + b end) "); Console.WriteLine("2 + 4 =" + calc.Add(2, 4)); CalcByConfig calc2 = new CalcByConfig(); Console.WriteLine("2 + 4 =" + calc2.Add(2, 4)); luaenv.DoString(@" xlua.hotfix(CS.CalcByConfig, 'Add', function(self, a, b) return a + b end) "); Console.WriteLine("2 + 4 =" + calc2.Add(2, 4)); //ÊÍ·Åhotfix luaenv.DoString(@" xlua.hotfix(CS.Calc, 'Add', nil) xlua.hotfix(CS.CalcByConfig, 'Add', nil) "); } catch (Exception e) { Console.WriteLine("Hotfix exception:" + e); } max = null; luaenv.Dispose(); }
public DelegateBridgeBase(int reference, LuaEnv luaenv) : base(reference, luaenv) { errorFuncRef = luaenv.errorFuncRef; }
// Use this for initialization void Start() { luaenv = new LuaEnv(); luaenv.DoString(script); Debug.Log("_G.a = " + luaenv.Global.Get<int>("a")); Debug.Log("_G.b = " + luaenv.Global.Get<string>("b")); Debug.Log("_G.c = " + luaenv.Global.Get<bool>("c")); DClass d = luaenv.Global.Get<DClass>("d");//映射到有对应字段的class,by value Debug.Log("_G.d = {f1=" + d.f1 + ", f2=" + d.f2 + "}"); Dictionary<string, double> d1 = luaenv.Global.Get<Dictionary<string, double>>("d");//映射到Dictionary<string, double>,by value Debug.Log("_G.d = {f1=" + d1["f1"] + ", f2=" + d1["f2"] + "}, d.Count=" + d1.Count); List<double> d2 = luaenv.Global.Get<List<double>>("d"); //映射到List<double>,by value Debug.Log("_G.d.len = " + d2.Count); ItfD d3 = luaenv.Global.Get<ItfD>("d"); //映射到interface实例,by ref,这个要求interface加到生成列表,否则会返回null,建议用法 d3.f2 = 1000; Debug.Log("_G.d = {f1=" + d3.f1 + ", f2=" + d3.f2 + "}"); Debug.Log("_G.d:add(1, 2)=" + d3.add(1, 2)); LuaTable d4 = luaenv.Global.Get<LuaTable>("d");//映射到LuaTable,by ref Debug.Log("_G.d = {f1=" + d4.Get<int>("f1") + ", f2=" + d4.Get<int>("f2") + "}"); Action e = luaenv.Global.Get<Action>("e");//映射到一个delgate,要求delegate加到生成列表,否则返回null,建议用法 e(); FDelegate f = luaenv.Global.Get<FDelegate>("f"); DClass d_ret; int f_ret = f(100, "John", out d_ret);//lua的多返回值映射:从左往右映射到c#的输出参数,输出参数包括返回值,out参数,ref参数 Debug.Log("ret.d = {f1=" + d_ret.f1 + ", f2=" + d_ret.f2 + "}, ret=" + f_ret); GetE ret_e = luaenv.Global.Get<GetE>("ret_e");//delegate可以返回更复杂的类型,甚至是另外一个delegate e = ret_e(); e(); LuaFunction d_e = luaenv.Global.Get<LuaFunction>("e"); d_e.Call(); }