diff options
Diffstat (limited to 'src/script/embed')
-rw-r--r-- | src/script/embed/boot.lua.h | 33 | ||||
-rw-r--r-- | src/script/embed/debug.lua.h | 72 |
2 files changed, 51 insertions, 54 deletions
diff --git a/src/script/embed/boot.lua.h b/src/script/embed/boot.lua.h index 223f354..cb61468 100644 --- a/src/script/embed/boot.lua.h +++ b/src/script/embed/boot.lua.h @@ -1,23 +1,7 @@ /* boot.lua */ static const char* boot_lua = R"( -local function _onEvent(e) - -- update keyboard status - if e.type == "keydown" then - jin.keyboard.set(e.key, true) - elseif e.type == "keyup" then - jin.keyboard.set(e.key, false) - end - - -- call user onEvent function - if jin.core.onEvent then - jin.core.onEvent(e) - end -end - -------------------------------------------------- --- init file system -------------------------------------------------- +-- init filesystem jin._argv[2] = jin._argv[2] or '.' jin.filesystem.init() jin.filesystem.mount(jin._argv[2]) @@ -54,13 +38,26 @@ function jin.core.run() local study = jin.graphics.study local onDraw = jin.core.onDraw local onUpdate = jin.core.onUpdate + local onEvent = jin.core.onEvent local present = jin.graphics.present + local setkey = jin.keyboard.set local dstatus = jin.debug.status local drender = jin.debug.render local fps = conf.fps - + + local _onEvent = function (e) + if e.type == "keydown" then + setkey(e.key, true) + elseif e.type == "keyup" then + setkey(e.key, false) + end + if onEvent then + onEvent(e) + end + end + if load then load() end diff --git a/src/script/embed/debug.lua.h b/src/script/embed/debug.lua.h index 7ccc99d..79c95ba 100644 --- a/src/script/embed/debug.lua.h +++ b/src/script/embed/debug.lua.h @@ -33,27 +33,27 @@ local refresh = true function jin.debug.init() debug = true - panel = jin.graphics.Canvas(jin.graphics.size()) + panel = jin.graphics.Canvas(jin.graphics.size()) end -- set buffer size function jin.debug.size(c) - bsize = c + bsize = c end function jin.debug.print(msg) - if not debug then return end - - msg = tostring(msg) - local tp = type(msg) - if tp ~= "string" and tp ~= "number" then - msg = string.format("print failed, expect string or number but get a %s", tp) - end - + if not debug then return end + + msg = tostring(msg) + local tp = type(msg) + if tp ~= "string" and tp ~= "number" then + msg = string.format("print failed, expect string or number but get a %s", tp) + end + -- remove the first one (old msg) - if #buffer >= bsize then - table.remove(buffer, 1) - end + if #buffer >= bsize then + table.remove(buffer, 1) + end buffer[#buffer + 1] = msg refresh = true @@ -61,33 +61,33 @@ end -- clear debug buffer function jin.debug.clear() - buffer = {} + buffer = {} end local function getStrHeight(str, lheight) - local h = lheight - if #str == 0 then - h = 0 - end - for i = 1, #str do - local c = string.sub(str, i, i) - if c == '\n' then - h = h + lheight - end - end - return h + local h = lheight + if #str == 0 then + h = 0 + end + for i = 1, #str do + local c = string.sub(str, i, i) + if c == '\n' then + h = h + lheight + end + end + return h end local function getBgQuad() - local width, height = 0, 0 - for i = 1, #buffer do - local w, h = jin.graphics.box( buffer[i], fsize, 1, lheight) - height = height + h - if width < w then - width = w - end - end - return width, height + local width, height = 0, 0 + for i = 1, #buffer do + local w, h = jin.graphics.box( buffer[i], fsize, 1, lheight) + height = height + h + if width < w then + width = w + end + end + return width, height end -- render to screen @@ -115,7 +115,7 @@ function jin.debug.render() y = y - h jin.graphics.write(msg, margin / 2, y - margin/ 2, fsize, 1, lheight) end - + jin.graphics.bind() refresh = false @@ -126,7 +126,7 @@ function jin.debug.render() end function jin.debug.status() - return debug + return debug end )";
\ No newline at end of file |