Skip to content

Commit

Permalink
update: 尝试修复 #165 问题
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxuuu committed Jun 25, 2024
1 parent 46d7b3e commit d677619
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions llcom/LuaEnv/LuaEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;

namespace llcom.LuaEnv
{
Expand All @@ -28,8 +29,9 @@ public class LuaEnv : IDisposable
private bool stop = false;//是否停止运行
private ConcurrentDictionary<int, CancellationTokenSource> timerPool =
new ConcurrentDictionary<int, CancellationTokenSource>();//timer取消标志池子
private static ConcurrentBag<LuaTaskData> toRun = new ConcurrentBag<LuaTaskData>();//待运行的池子
private ConcurrentBag<LuaTaskData> toRun = new ConcurrentBag<LuaTaskData>();//待运行的池子
private readonly object taskLock = new object();
private XLua.LuaFunction triggerCB = null;

/// <summary>
/// 发出报错信息
Expand Down Expand Up @@ -83,8 +85,7 @@ private void runTask()
{
LuaTaskData task;
toRun.TryTake(out task);//取出来一个任务
var cb = lua.Global.Get<XLua.LuaTable>("sys").Get<XLua.LuaFunction>("tiggerCB");
cb.Call(task.id, task.type, task.data);//跑
triggerCB.Call(task.id, task.type, task.data);//跑
}
catch (Exception e)
{
Expand Down Expand Up @@ -187,6 +188,7 @@ public LuaEnv(object input = null)
if (input != null)
lua.Global.SetInPath("lua", input);//传递输入值
lock (taskLock) lua.DoString(sysCode);
triggerCB = lua.Global.Get<XLua.LuaTable>("sys").Get<XLua.LuaFunction>("tiggerCB");
lua.Global.SetInPath("@this", this);//自己传给自己

//加上需要require的路径
Expand Down
8 changes: 4 additions & 4 deletions llcom/LuaEnv/LuaRunEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;

namespace llcom.LuaEnv
{
Expand All @@ -18,6 +19,7 @@ class LuaRunEnv
private static ConcurrentDictionary<int, CancellationTokenSource> pool =
new ConcurrentDictionary<int, CancellationTokenSource>();//timer回调池子
private static ConcurrentBag<LuaPool> toRun = new ConcurrentBag<LuaPool>();//待运行的池子
private static XLua.LuaFunction triggerCB = null;

public static bool isRunning = false;
public static bool canRun = false;
Expand Down Expand Up @@ -71,10 +73,7 @@ private static void runTigger()
{
LuaPool temp;
toRun.TryTake(out temp);
XLua.LuaFunction f = null;
//while (f == null)
f = lua.Global.Get<XLua.LuaFunction>("tiggerCB");
f.Call(temp.id, temp.type, temp.data);
triggerCB.Call(temp.id, temp.type, temp.data);
}
catch (Exception le)
{
Expand Down Expand Up @@ -190,6 +189,7 @@ public static void New(string file)
{
lua.Global.SetInPath("runType", "script");//一次性处理标志
LuaLoader.Initial(lua);
triggerCB = lua.Global.Get<XLua.LuaFunction>("tiggerCB");
lua.DoString($"require '{file.Replace("/", ".").Substring(0, file.Length - 4)}'");
}
}
Expand Down

0 comments on commit d677619

Please sign in to comment.