Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit 7313942

Browse files
committed
测试xlua使用modules加载其他lua脚本
1 parent 8172f8d commit 7313942

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

Assets/Game/HotFix/Main.lua.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
local Test=require("Test")
2+
13
function Start()
24
print("lua start")
5+
Test:Start()
36
end
47

58
function Update()

Assets/Game/HotFix/Test.lua.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
local M={}
2+
3+
function M.Start()
4+
print("Test lua start")
5+
end
6+
7+
function Update()
8+
print("lua update...")
9+
end
10+
11+
function Close()
12+
print("lua close")
13+
end
14+
15+
return M

Assets/Game/HotFix/Test.lua.txt.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/GameFramework/HotFix/HotFixManager.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ public sealed class HotFixManager:GameFrameworkModule,IUpdate
3434
Action _update;
3535
Action _close;
3636

37+
//lua 计时
38+
private static float _lastGCTime = 0.0f;
39+
//lua tick的间隔时间
40+
private const float _luaTickInterval = 1.0f;
41+
42+
3743
/// <summary>
3844
/// 加载热更新脚本
3945
/// </summary>
@@ -77,6 +83,13 @@ private byte[] CustomLoader(ref string filePath)
7783
public void OnUpdate()
7884
{
7985
_update?.Invoke();
86+
87+
//每隔一段时间对lua进行一次GC回收
88+
if (Time.time - _lastGCTime > _luaTickInterval)
89+
{
90+
_luaEnv.Tick();
91+
_lastGCTime = Time.time;
92+
}
8093
}
8194

8295
public override void OnClose()

0 commit comments

Comments
 (0)