- Added floor, ceil and abs to reactive env
- Changed BasaltProgram env (not finished) - Fixed program not setting running to false once coroutine is dead
This commit is contained in:
@@ -31,30 +31,43 @@ function BasaltProgram.new(program)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function createShellEnv(dir)
|
||||||
|
local env = { shell = shell, multishell = multishell }
|
||||||
|
env.require, env.package = newPackage(env, dir)
|
||||||
|
return env
|
||||||
|
end
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
function BasaltProgram:run(path, width, height)
|
function BasaltProgram:run(path, width, height)
|
||||||
self.window = window.create(term.current(), 1, 1, width, height, false)
|
self.window = window.create(self.program:getBaseFrame():getTerm(), 1, 1, width, height, false)
|
||||||
local pPath = shell.resolveProgram(path)
|
local pPath = shell.resolveProgram(path)
|
||||||
if(pPath~=nil)then
|
if(pPath~=nil)then
|
||||||
if(fs.exists(pPath)) then
|
if(fs.exists(pPath)) then
|
||||||
local file = fs.open(pPath, "r")
|
local file = fs.open(pPath, "r")
|
||||||
local content = file.readAll()
|
local content = file.readAll()
|
||||||
file.close()
|
file.close()
|
||||||
local env = setmetatable(self.env, {__index=_ENV})
|
--[[local env = setmetatable(self.env, {__index=_ENV})
|
||||||
env.shell = shell
|
env.shell = shell
|
||||||
env.term = self.window
|
env.term = self.window
|
||||||
env.require, env.package = newPackage(env, fs.getDir(pPath))
|
env.require, env.package = newPackage(env, fs.getDir(pPath))
|
||||||
env.term.current = term.current
|
env.term.current = term.current
|
||||||
env.term.redirect = term.redirect
|
env.term.redirect = term.redirect
|
||||||
env.term.native = term.native
|
env.term.native = term.native]]
|
||||||
|
|
||||||
|
local env = setmetatable(createShellEnv(fs.getDir(path)), { __index = _ENV })
|
||||||
|
env.term = self.window
|
||||||
|
env.term.current = term.current
|
||||||
|
env.term.native = function ()
|
||||||
|
return self.window
|
||||||
|
end
|
||||||
|
for k,v in pairs(self.env) do
|
||||||
|
env[k] = v
|
||||||
|
end
|
||||||
|
|
||||||
self.coroutine = coroutine.create(function()
|
self.coroutine = coroutine.create(function()
|
||||||
local program = load(content, path, "bt", env)
|
local program = load(content, "@/" .. path, nil, env)
|
||||||
if program then
|
if program then
|
||||||
local current = term.current()
|
|
||||||
term.redirect(self.window)
|
|
||||||
local result = program(path, table.unpack(self.args))
|
local result = program(path, table.unpack(self.args))
|
||||||
term.redirect(current)
|
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@@ -90,7 +103,7 @@ end
|
|||||||
|
|
||||||
---@private
|
---@private
|
||||||
function BasaltProgram:resume(event, ...)
|
function BasaltProgram:resume(event, ...)
|
||||||
if self.coroutine==nil or coroutine.status(self.coroutine)=="dead" then return end
|
if self.coroutine==nil or coroutine.status(self.coroutine)=="dead" then self.program.set("running", false) return end
|
||||||
if(self.filter~=nil)then
|
if(self.filter~=nil)then
|
||||||
if(event~=self.filter)then return end
|
if(event~=self.filter)then return end
|
||||||
self.filter=nil
|
self.filter=nil
|
||||||
@@ -118,7 +131,7 @@ end
|
|||||||
|
|
||||||
---@private
|
---@private
|
||||||
function BasaltProgram:stop()
|
function BasaltProgram:stop()
|
||||||
if self.coroutine==nil or coroutine.status(self.coroutine)=="dead" then return end
|
if self.coroutine==nil or coroutine.status(self.coroutine)=="dead" then self.program.set("running", false) return end
|
||||||
coroutine.close(self.coroutine)
|
coroutine.close(self.coroutine)
|
||||||
self.coroutine = nil
|
self.coroutine = nil
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ local function errorHandler(err)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local ok, result = pcall(require, "main")
|
local ok, result = pcall(require, "main")
|
||||||
|
package.loaded.main = nil
|
||||||
|
package.loaded.log = nil
|
||||||
|
|
||||||
package.path = defaultPath
|
package.path = defaultPath
|
||||||
if not ok then
|
if not ok then
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ local lazyElementCount = 10
|
|||||||
local lazyElementsTimer = 0
|
local lazyElementsTimer = 0
|
||||||
local isLazyElementsTimerActive = false
|
local isLazyElementsTimerActive = false
|
||||||
|
|
||||||
|
|
||||||
local function queueLazyElements()
|
local function queueLazyElements()
|
||||||
if(isLazyElementsTimerActive)then return end
|
if(isLazyElementsTimerActive)then return end
|
||||||
lazyElementsTimer = os.startTimer(0.2)
|
lazyElementsTimer = os.startTimer(0.2)
|
||||||
@@ -237,6 +236,7 @@ local function updateEvent(event, ...)
|
|||||||
for _, frame in pairs(activeFrames) do
|
for _, frame in pairs(activeFrames) do
|
||||||
frame:dispatchEvent(event, ...)
|
frame:dispatchEvent(event, ...)
|
||||||
end
|
end
|
||||||
|
--activeFrames[main]:dispatchEvent(event, ...) -- continue here
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, func in ipairs(basalt._schedule) do
|
for _, func in ipairs(basalt._schedule) do
|
||||||
|
|||||||
@@ -14,7 +14,10 @@ local mathEnv = {
|
|||||||
end,
|
end,
|
||||||
round = function(val)
|
round = function(val)
|
||||||
return math.floor(val + 0.5)
|
return math.floor(val + 0.5)
|
||||||
end
|
end,
|
||||||
|
floor = math.floor,
|
||||||
|
ceil = math.ceil,
|
||||||
|
abs = math.abs
|
||||||
}
|
}
|
||||||
|
|
||||||
local function parseExpression(expr, element, propName)
|
local function parseExpression(expr, element, propName)
|
||||||
|
|||||||
Reference in New Issue
Block a user