From ac7118092ad573e6381ec7fc07c2bbed12791cde Mon Sep 17 00:00:00 2001 From: Ryan Ward Date: Sat, 26 Jan 2019 19:45:50 -0500 Subject: [PATCH] What have I undertook added stuff, fixed more bugs, more documentation, more pain and suffering This is taking too long, but ill push through hahahahahahahahha --- New Text Document.txt | 0 WeCanWriteEm.txt | 1 - parseManager/init.lua | 51 ++++++++++++++++++++++++++--- test.dms | 14 ++++++++ test.lua | 76 ++++++++++++++++++++++++++++--------------- test2.lua | 16 ++++++--- textadventure.dms | 45 +++++++++++++------------ 7 files changed, 144 insertions(+), 59 deletions(-) create mode 100644 New Text Document.txt diff --git a/New Text Document.txt b/New Text Document.txt new file mode 100644 index 0000000..e69de29 diff --git a/WeCanWriteEm.txt b/WeCanWriteEm.txt index 32f95c0..e69de29 100644 --- a/WeCanWriteEm.txt +++ b/WeCanWriteEm.txt @@ -1 +0,0 @@ -hi \ No newline at end of file diff --git a/parseManager/init.lua b/parseManager/init.lua index 1fd63fc..2190272 100644 --- a/parseManager/init.lua +++ b/parseManager/init.lua @@ -14,6 +14,52 @@ parseManager.methods={} parseManager.lastCall=nil parseManager.currentHandle=nil parseManager.currentHandleName=nil +parseManager.state = {} +parseManager.active = true +function parseManager:mainRunner(block) + local t = self:next(block) + if not t then return nil end + if t.Type=="text" then + io.write(t.text) + io.read() + t=self:next() + elseif t.Type=="condition" then + t=self:next() + elseif t.Type=="assignment" then + t=self:next() + elseif t.Type=="label" then + t=self:next() + elseif t.Type=="method" then + t=self:next() + elseif t.Type=="choice" then + print(t.text) + for i=1,#t.choices do + print(i..". "..t.choices[i]) + end + io.write("Choose#: ") + cm=tonumber(io.read()) + t=self:next(nil,cm,nil,t) + elseif t.Type=="end" then + if t.text=="leaking" then -- go directly to the block right under the current block if it exists + t=self:next() + else + os.exit() + end + elseif t.Type=="error" then + error(t.text) + else + t=self:next() + end + -- if true return t, else return false + return self.active and t +end +function parseManager:run(block) + local dat = self:mainRunner(block) + while dat do + dat = self:mainRunner() + end + -- print("done") +end function readonlytable(tab) return setmetatable({},{ __index=tab, @@ -28,9 +74,6 @@ function parseManager:debug(...) print("",...) end end -function parseManager:defualtRunner(func) - -- -end function parseManager:newENV() local env={} function env:getParent() @@ -1208,8 +1251,6 @@ function parseManager:next(block,choice) local args=self:dataToValue(data.args) local Func local Ext=false - -- table.print(data.args) - table.print(args) if type(data.Func)=="table" then Ext=true Func=self.currentENV[data.Func[1]][data.Func[2]] diff --git a/test.dms b/test.dms index e69de29..a251170 100644 --- a/test.dms +++ b/test.dms @@ -0,0 +1,14 @@ +ENTRY TEST +[TEST]{ + newLightThread("TEST2") + ::loop:: + print("Hello!") + sleep(.5) + GOTO("loop") +} +[TEST2]{ + ::loop:: + print("Hi!") + sleep(1) + GOTO("loop") +} \ No newline at end of file diff --git a/test.lua b/test.lua index 5189b80..bdb0a84 100644 --- a/test.lua +++ b/test.lua @@ -1,36 +1,25 @@ package.path="?/init.lua;lua/?/init.lua;lua/?.lua;"..package.path local bin = require("bin") ---~ local multi = require("multi") +local multi = require("multi") require("parseManager") require("bit") ---~ parseManager:define({ ---~ rshift=function(self,a,b) ---~ return bit.rshift(a,b) ---~ end, ---~ lshift=function(self,a,b) ---~ return bit.lshift(a,b) ---~ end, ---~ testfunc=function(self,a,b,c) ---~ print(tostring(a).." "..tostring(b).." "..tostring(c)) ---~ end ---~ }) -test=parseManager:load("textadventure.dms") +test=parseManager:load("test.dms") print(test:dump()) -t=test:next() -while true do - if not t then break end +--Code would happen here anyway +local runner = function(block,t) + if not t then return nil end if t.Type=="text" then io.write(t.text) io.read() - t=test:next() + t=self:next() elseif t.Type=="condition" then - t=test:next() + t=self:next() elseif t.Type=="assignment" then - t=test:next() + t=self:next() elseif t.Type=="label" then - t=test:next() + t=self:next() elseif t.Type=="method" then - t=test:next() + t=self:next() elseif t.Type=="choice" then print(t.text) for i=1,#t.choices do @@ -38,19 +27,52 @@ while true do end io.write("Choose#: ") cm=tonumber(io.read()) - t=test:next(nil,cm,nil,t) + t=self:next(nil,cm,nil,t) elseif t.Type=="end" then if t.text=="leaking" then -- go directly to the block right under the current block if it exists - t=test:next() + t=self:next() else os.exit() end elseif t.Type=="error" then error(t.text) else - t=test:next() + t=self:next() end + return t end ---["vars"]={"\1%"..string.char(mathAss+64)} ---cmds[#cmds+1]={Func="MOD",args={l,(r or "")}} --- +test.mainRunner = runner +test.active = false +multi:newThread("Parse Manager Main State",function() + local dat = self:mainRunner(nil,self:next()) + while dat do + thread.skip() + dat = self:mainRunner(nil,dat) + end +end) +function test:run() + multi:mainloop() +end +test:define{ + sleep = function(self,n) + thread.sleep(n) + end, + newLightThread = function(self,block) + local state = parseManager:load(self.currentChunk.path) + state.mainENV = self.mainENV + state.mainRunner = runner + multi:newThread("Parse Manager State",function() + local dat = state:mainRunner(nil,state:next()) + while dat do + thread.skip() + dat = state:mainRunner(nil,dat) + end + end) + end +} +--End of injecting +--~ test:run() +multi:newThread("",function() + print("Threading works") +end) +multi:mainloop() diff --git a/test2.lua b/test2.lua index b53d8db..a4356cb 100644 --- a/test2.lua +++ b/test2.lua @@ -1,8 +1,8 @@ -local GLOBAL, sThread = require("multi.integration.lanesManager").init() -GLOBAL["Test"]=true -multi:newSystemThread("NewThread",function(blck,path,name) - print(GLOBAL["Test"]) -end) +--~ local GLOBAL, sThread = require("multi.integration.lanesManager").init() +--~ GLOBAL["Test"]=true +--~ multi:newSystemThread("NewThread",function(blck,path,name) +--~ print(GLOBAL["Test"]) +--~ end) --~ io.flush() --~ i = io.input() --~ i:seek("cur") @@ -19,3 +19,9 @@ end) --~ io.write("\b") --~ io.flush() --~ io.read() +bool = true +function test() + local t = {} + return bool and t +end +print(test()) diff --git a/textadventure.dms b/textadventure.dms index aca12cb..7e2d107 100644 --- a/textadventure.dms +++ b/textadventure.dms @@ -6,25 +6,28 @@ ENTRY MAIN print("We cannot use the filesystem or the extendedDefine module! Exiting program!") QUIT() ::define:: - // USING filesystem as bin - // USING extendedDefine - // setVar("name","Thread Test") - // newThread("LoopTest") - // in = getInput("Enter Something: ") - // file = bin.new(in) - // file:tofile("WeCanWriteEm.txt") - "Let's test simple object creation" - obj = [] - obj.test = say - obj.test("Hello!") - "Hmm..." + USING filesystem as bin + USING extendedDefine + setVar("name","Thread Test") + newThread("LoopTest") + in = getInput("Enter Something: ") + file = bin.new(in) + file:tofile("WeCanWriteEm.txt") + test(1,2) + "We are here now" + "why no work" + "?" } -// [LoopTest]{ - // a=0 - // name = getVar("name") - // ::loop:: - // a=a+1 - // test("$name$ $a$") - // sleep(1) - // GOTO("loop") -// } \ No newline at end of file +[test:function(a,b)]{ + print("This works right? $a$ $b$") + return True +} +[LoopTest]{ + a=0 + name = getVar("name") + ::loop:: + a=a+1 + test("$name$ $a$") + sleep(1) + GOTO("loop") +} \ No newline at end of file