Functions rework in progress
Currently working of functions. Right now external hooking are not working. Some times they work great, other times it is hilighy glitched. Internal functions work as expected and really well now. However when called outside things tend to go wrong
This commit is contained in:
parent
3af881e1a9
commit
bfb34916e3
@ -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
|
||||
|
||||
34
test.dms
34
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
|
||||
}
|
||||
7
test.lua
7
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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user