mirror of
https://github.com/Ale32bit/Capy64.git
synced 2025-01-18 10:36:44 +00:00
Use Lua threads to conserve data from tasks
This commit is contained in:
parent
0e4d3c135a
commit
d137c46ed9
2 changed files with 21 additions and 11 deletions
|
@ -96,10 +96,12 @@ public class Machine : IComponent
|
|||
{
|
||||
var L = Lua.FromIntPtr(state);
|
||||
|
||||
var task = new Objects.TaskMeta.RuntimeTask("test");
|
||||
|
||||
ObjectManager.PushObject(L, task);
|
||||
L.SetMetaTable(Objects.TaskMeta.ObjectType);
|
||||
var task = Objects.TaskMeta.Push(L, "test");
|
||||
task.Fulfill(lk => {
|
||||
lk.NewTable();
|
||||
lk.PushString("value");
|
||||
lk.SetField(-2, "key");
|
||||
});
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -77,13 +77,20 @@ public class TaskMeta : IComponent
|
|||
{
|
||||
Status = TaskStatus.Succeeded;
|
||||
|
||||
Result = lk;
|
||||
|
||||
_game.LuaRuntime.QueueEvent("task_finish", LK =>
|
||||
{
|
||||
LK.PushString(Guid.ToString());
|
||||
|
||||
lk(LK);
|
||||
// Create Lua thread to store Lua native result data
|
||||
Result = LK.NewThread();
|
||||
var thread = (Lua)Result;
|
||||
LK.Pop(1);
|
||||
|
||||
lk(thread);
|
||||
|
||||
// Push copy of value on top and move it to LK
|
||||
thread.PushCopy(-1);
|
||||
thread.XMove(LK, 1);
|
||||
|
||||
LK.PushNil();
|
||||
|
||||
|
@ -139,7 +146,7 @@ public class TaskMeta : IComponent
|
|||
new()
|
||||
{
|
||||
name = "getError",
|
||||
function = L_GetResult,
|
||||
function = L_GetError,
|
||||
},
|
||||
new(),
|
||||
};
|
||||
|
@ -282,10 +289,11 @@ public class TaskMeta : IComponent
|
|||
|
||||
if (task.Status == TaskStatus.Succeeded)
|
||||
{
|
||||
if (task.Result is Action<Lua> lk)
|
||||
if (task.Result is Lua thread)
|
||||
{
|
||||
// todo: make use of first-generated data
|
||||
lk(L);
|
||||
// Push copy of value on top and move it to LK
|
||||
thread.PushCopy(-1);
|
||||
thread.XMove(L, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue