diff --git a/parseManager/init.lua b/parseManager/init.lua index ac2ea94..8fccf2e 100644 --- a/parseManager/init.lua +++ b/parseManager/init.lua @@ -1083,7 +1083,63 @@ function parseManager:define(t) self.methods[i]=v end end +function parseManager:handleChoice(func) + self.choiceManager = func +end function parseManager:Invoke(func,vars,...) + if not self.isrunning then + self.isrunning = true + local t=self:next() + local name=func + local func=self.chunks[func] + if func then + if func.type:sub(1,1)=="f" then + local returndata={} + self.fArgs={...} + if #self.fArgs==0 then + self.fArgs={self.lastCall} + end + push(self.stack,{chunk=self.currentChunk,pos=self.currentChunk.pos,env=self.currentENV,vars=vars}) + self.currentENV = self:newENV() + self.methods.JUMP(self,name) + -- return + else + self:pushError("Attempt to call a non function block!",name) + end + else + self:pushError("Attempt to call a non existing function!",name) + end + while t do + 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 + if self.choiceManager then + t=self:choiceManager(t) + else + t=self:next(nil,math.random(1,#t[1])) + end + elseif t.Type=="end" then + if t.text=="leaking" then + t=self:next() + end + elseif t.Type=="error" then + error(t.text) + else + t=self:next() + end + end + return + end local name=func local func=self.chunks[func] if func then @@ -1199,7 +1255,12 @@ function parseManager:parseHeader(data) local var,inwards = dat:match("(.-)%[(.+)%]") local ind = parseManager.split(inwards,":") if #ind==2 then - return self.currentENV[dat:match("(.-)%[")]:sub(ind[1],ind[2]) + local str = self.currentENV[dat:match("(.-)%[")] + if tonumber(ind[1])<0 and tonumber(ind[2])>0 then + return str:reverse():sub(math.abs(tonumber(ind[1])),-math.abs(tonumber(ind[2]))) + else + return str:sub(ind[1],ind[2]) + end end end elseif not type(self.currentENV[dat])=="table" then @@ -1276,9 +1337,13 @@ function parseManager:pairAssign(vars,vals,envF) end function parseManager:next(block,choice) if self.entry then + self.isrunning = true block = block or self.entry self.entry = nil end + if block then + self.isrunning = true + end local chunk = self.currentChunk or self.chunks[block] or self.chunks["START"] self.currentChunk=chunk if choice then @@ -1293,12 +1358,12 @@ function parseManager:next(block,choice) end local ret local data=chunk[chunk.pos] - if not data then return end + if not data then self.isrunning = false return end if data.Type=="label" then chunk.pos=chunk.pos+1 data=chunk[chunk.pos] end - if not data then return end + if not data then self.isrunning = false return end chunk.pos=chunk.pos+1 self:debug("TYPE: "..data.Type) if data.Type=="text" then diff --git a/test.dms b/test.dms index 71e356b..0feadef 100644 --- a/test.dms +++ b/test.dms @@ -2,11 +2,14 @@ ENTRY MAIN USING extendedDefine VERSION 4.1 [MAIN]{ - test = [1,2,3,4,5,6,7,8,9,10] - t=0 - test2 = "Hello" - str = $test2[1:-2]$ - print(str) + // test = [1,2,3,4,5,6,7,8,9,10] + // t=0 + // test2 = "Hello" + // str = $test2[1:-1]$ + // print("$test2[-1:1]$") + // print(str) + // t=testfunc(1,2) + // print(t) // for i = 1,10 < // "Choice Test: $test[1]$" < // "A" setGlobalVar("t",1) @@ -16,4 +19,25 @@ VERSION 4.1 // > // ::leave:: // print("t = $t$ i = $i$") + val = 0 + multi = external() + multi:newTLoop(testfunc,1) + // multi:newTLoop(testfunc2) + // alarm = multi:newAlarm(3) + // alarm:OnRing(testfunc) + print("Hooked function!") +} +[testfunc:function()]{ + val = val + 1 + print("Called $val$ times!") + return True +} +[testfunc2:function()]{ + "Test"< + "1" print("A") + "2" print("B") + "3" print("C") + > + // print("Yo whats up!") + return True } \ No newline at end of file diff --git a/test.dmsc b/test.dmsc index bf7f4db..e8567f7 100644 Binary files a/test.dmsc and b/test.dmsc differ diff --git a/test.lua b/test.lua index 7f16e4e..a059c82 100644 --- a/test.lua +++ b/test.lua @@ -2,9 +2,15 @@ package.path="?/init.lua;lua/?/init.lua;lua/?.lua;"..package.path local bin = require("bin") local multi = require("multi") require("parseManager") +require("multi") test=parseManager:compileToFile("test.dms","test.dmsc")--load("StoryTest/init.dms") --~ test = parseManager:loadCompiled("test.dmsc") print(test:dump()) +test:define{ + external=function(self) + return multi + end +} t=test:next() while t do if t.Type=="text" then @@ -39,3 +45,4 @@ while t do t=test:next() end end +multi:mainloop()