From 441ca0faccbfaddccabdde8b1104e923c1af258b Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine \" Monoids" Date: Fri, 23 Sep 2022 16:21:23 +0300 Subject: [PATCH] help --- actorsTest.xml | 6 +++ main.xml | 115 +++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 113 insertions(+), 8 deletions(-) create mode 100644 actorsTest.xml diff --git a/actorsTest.xml b/actorsTest.xml new file mode 100644 index 0000000..ce7fb36 --- /dev/null +++ b/actorsTest.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/main.xml b/main.xml index bebdb60..e396c77 100644 --- a/main.xml +++ b/main.xml @@ -288,8 +288,29 @@ -- actors local actorQueue = {} + local actorAssociationQueue = {} + + local actorTree = {} + local currentPath + local pastPaths = {} local currentActor = nil + local function findFirstActor(path) + for i, v in ipairs(path) do + if v.type or v.file then + return v, i + end + end + end + + local function findFirstActorFrame(path) + for i, v in ipairs(path) do + if not v.type and not v.file then + return v, i + end + end + end + oat._actor = {} function oat._actor.next() @@ -337,14 +358,17 @@ function oat._actor.init(self) currentActor.init(self) + currentActor = nil -- shouldn't be needed from now on end function oat._actor.initFrame(self) - local nextChild = self(2) + print('initiating an actorframe') + --local nextChild = self(2) self:SetDrawFunction(function() - if nextChild then - nextChild:Draw() - end + --if nextChild then + -- nextChild:Draw() + --end + -- TODO end) end @@ -352,6 +376,7 @@ local queue = {} local initCommands = {} local lockedActor + local queueRepresentation return setmetatable({}, { __index = function(self, key) @@ -365,8 +390,17 @@ end return val end + if key == '__queue' then + return queueRepresentation + end + if key == '__queueRepresentation' then + return function(q) + queueRepresentation = q + end + end if key == '__lock' then return function(actor) + if lockedActor then return end for _, v in ipairs(queue) do local func = actor[v[1]] if not func then @@ -406,6 +440,7 @@ end end initCommands = {} + queueRepresentation = nil -- to make mr. Garbage Collector's job easier end else return function(...) @@ -420,7 +455,7 @@ __newindex = function() error('uranium: cannot set properties on actors!', 2) end, - __tostring = function() return name end, + __tostring = function() return 'Proxy of ' .. name end, __name = name }) end @@ -431,11 +466,11 @@ local actor = createProxyActor(type) table.insert(actorQueue, { type = type, - file = nil, init = function(a) actor.__lock(a) end }) + actor.__queueRepresentation(actorQueue[#actorQueue]) return actor end end @@ -458,6 +493,20 @@ actor.__lock(a) end }) + actor.__queueRepresentation(actorQueue[#actorQueue]) + return actor + end + + function ActorFrame() + if actorsInitialized then error('uranium: cannot create an actor during runtime!!', 2) end + local actor = createProxyActor('ActorFrame') + table.insert(actorQueue, { + type = 'ActorFrame', + init = function(a) + actor.__lock(a) + end + }) + actor.__queueRepresentation(actorQueue[#actorQueue]) return actor end @@ -496,6 +545,7 @@ end end }) + actor.__queueRepresentation(actorQueue[#actorQueue]) return actor end @@ -510,6 +560,7 @@ actor.__lock(a) end }) + actor.__queueRepresentation(actorQueue[#actorQueue]) return actor end @@ -524,6 +575,7 @@ actor.__lock(a) end }) + actor.__queueRepresentation(actorQueue[#actorQueue]) return actor end @@ -538,16 +590,62 @@ actor.__lock(a) end }) + actor.__queueRepresentation(actorQueue[#actorQueue]) return actor end + function addChild(frame, actor) + actorAssociationQueue[actor.__queue] = frame.__queue + end + + local function transformQueueToTree() + local tree = {} + local paths = {} + local iter = 0 + while #actorQueue > 0 do + iter = iter + 1 + if iter > 999999 then + error('uranium: failed to transform queue to tree: reached maximum iteration limit! is there an actor with an invalid actorframe?') + end + for i = #actorQueue, 1, -1 do + v = actorQueue[i] + local insertInto + if not actorAssociationQueue[v] then + insertInto = tree + else + if paths[actorAssociationQueue[v]] then + insertInto = paths[actorAssociationQueue[v]] + end + end + if insertInto then + if v.type == 'ActorFrame' then + table.insert(insertInto, {init = v.init}) + table.remove(actorQueue, i) + paths[v] = insertInto[#insertInto] + else + table.insert(insertInto, v) + table.remove(actorQueue, i) + end + end + end + end + actorTree = tree + end + local success, result = pcall(function() - require('main') + --require('main') + --require('stdlib.util') end) if success then luaobj = result + --local queue = actorQueue + --actorQueue = deepcopy(actorQueue) + --transformQueueToTree() + --Trace(fullDump(actorTree)) + --currentPath = actorTree + self:addcommand('On', onCommand) self:addcommand('Ready', screen_ready_command) self:addcommand('Off', exit) @@ -570,6 +668,7 @@ -- By removing the command after it's done, it can only ever run once self:removecommand('Init') end"> - + + \ No newline at end of file