diff --git a/audiotest.dms b/audiotest.dms new file mode 100644 index 0000000..729849a --- /dev/null +++ b/audiotest.dms @@ -0,0 +1,30 @@ +ENTRY init +USING audio as audio +[init]{ + bgm = audio:new("Audio/Lost World - myuu.ogg") + bgm:play(1) + bgm:setVolume(.1) + JUMP("CHOOSE") +} +[CHOOSE]{ + "Choose"< + "fade in" JUMP("FADEIN") + "fade out" JUMP("FADEOUT") + "exit" JUMP("quit") + > +} +[FADEIN]{ + for x = 100,1,-1 < + sleep(.1) + bgm:setVolume(100/x) + > +} +[FADEOUT]{ + for x = 100,1,-1 < + sleep(.1) + bgm:setVolume(x/100) + > +} +[quit]{ + QUIT() +} \ No newline at end of file diff --git a/hey.txt b/hey.txt new file mode 100644 index 0000000..5cc5f62 --- /dev/null +++ b/hey.txt @@ -0,0 +1 @@ +We can write data like this too! \ No newline at end of file diff --git a/parseManager/audio.lua b/parseManager/audio.lua index 1b4ef06..7e508ae 100644 --- a/parseManager/audio.lua +++ b/parseManager/audio.lua @@ -6,6 +6,7 @@ function audio:new(path) local c = {} c.path = path c.handle = proAudio.sampleFromFile(path) + print("Created:",c.handle) setmetatable(c,audio) return c end @@ -22,8 +23,9 @@ function audio:stop() proAudio.soundStop(self.handle) end function audio:setVolume(volume) + local volume = tonumber(volume) or 1 proAudio.soundUpdate(self.handle,volume,volume) end function parseManager:audio() return audio -end \ No newline at end of file +end diff --git a/parseManager/init.lua b/parseManager/init.lua index 0c5f66f..7560de4 100644 --- a/parseManager/init.lua +++ b/parseManager/init.lua @@ -74,15 +74,24 @@ function parseManager:DISABLE(fn) self.stats[string.lower(fn)]=false end function parseManager:USING(fn,name) - local m = require("parseManager."..fn) + local loaded, m = pcall(require,"parseManager."..fn) + if not loaded then + loaded, m = pcall(require,fn) + if not loaded then + self:pushError("Unable to load module "..fn.."!") + end + end self.usings[#self.usings]={fn,name} if not m then self:pushError(fn.." was not found as an import that can be used!") else - local ret = self[fn](self) - if ret then - self.mainENV[name or fn]=ret + local ret + if self[fn] then + ret = self[fn](self) + else + ret = m end + self.mainENV[name or fn]=ret end end --[[ @@ -852,13 +861,11 @@ local function extract(dat,name) return dat end end +parseManager.isInternal={} function parseManager:compile(name,ctype,data) local isFBlock,FBArgs=ctype:match("(f)unction%((.*)%)") --Check if we are dealing with a FBlock if isFBlock=="f" then - if not self.isInternal then - self.isInternal = {} - end self.cFuncs[name]=true -- if self.methods[name] then -- self:pushError("You cannot create a method with the same name as a standard method or duplicate method names!",name) @@ -918,9 +925,9 @@ function parseManager:compile(name,ctype,data) if cmd==1 then local t = extract(dat[7],name) if type(t)=="string" then - t="+"..t + t="+"..(t~="" and t or 1) end - -- parseManager.print(dat[2] .. (t or "+1")) + parseManager.print(dat[2] .. (t or "+1")) self:compileAssign(dat[2],dat[2] .. (t or "+1"),name) self:compileCondition(dat[2].."=="..tonumber(dat[4])+(tonumber(dat[7]) or 1),"GOTO(\""..s.."\")","GOTO(\""..dat[1].."\")",name) data[i] = "::"..s.."::" @@ -1288,7 +1295,9 @@ function parseManager:next(block,choice) if data.Type=="label" then chunk.pos=chunk.pos+1 data=chunk[chunk.pos] - IRET = self.__LABEL(data.label,data.pos) + if data then + IRET = self.__LABEL(data.label,data.pos) + end end if not data then self.isrunning = false return end chunk.pos=chunk.pos+1 @@ -1313,7 +1322,7 @@ function parseManager:next(block,choice) else Func=self.methods[data.Func] end - if self.isInternal[data.Func] then + if not self.methods[data.Func] then rets={Func(unpack(args))} else rets={Func(self,unpack(args))} diff --git a/test.lua b/test.lua index 96cc993..5ba21c8 100644 --- a/test.lua +++ b/test.lua @@ -4,7 +4,7 @@ local bin = require("bin") local multi = require("multi") require("parseManager") require("multi") -test=parseManager:load("test.dms")--parseManager:compileToFile("test.dms","test.dmsc")-- +test=parseManager:load("audiotest.dms")--parseManager:compileToFile("test.dms","test.dmsc")-- test:define{ external = function(self) return multi @@ -14,11 +14,8 @@ test:define{ end } parseManager.print(test:dump()) ---~ test = parseManager:loadCompiled("test.dmsc") ---~ print(test.methods.DoMe(2)) ---~ print(test.methods.DoMe(1,2)) +print(test:dump()) local active = true while active do active = test:think() end ---~ multi:mainloop() diff --git a/test2.dms b/test2.dms new file mode 100644 index 0000000..e63e3a8 --- /dev/null +++ b/test2.dms @@ -0,0 +1,16 @@ +USING multi as multi +USING bin as bin +ENTRY INIT +[INIT]{ + // "Hi!" + // "Lets do a test" + file = bin.new() + file.data = "We can write data like this too!" + print(file) + file:tofile("hey.txt") + // multi:newTLoop(test,1) + // multi:mainloop() +} +[test:function(self,a)]{ + print("Loops: $a$") +} \ No newline at end of file