aboutsummaryrefslogtreecommitdiff
path: root/src/lua/embed
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/embed')
-rw-r--r--src/lua/embed/boot.lua132
-rw-r--r--src/lua/embed/boot.lua.h143
-rw-r--r--src/lua/embed/debug.lua128
-rw-r--r--src/lua/embed/debug.lua.h125
-rw-r--r--src/lua/embed/embed.h51
-rw-r--r--src/lua/embed/graphics.lua6
-rw-r--r--src/lua/embed/graphics.lua.h8
-rw-r--r--src/lua/embed/keyboard.lua16
-rw-r--r--src/lua/embed/keyboard.lua.h13
-rw-r--r--src/lua/embed/mouse.lua15
-rw-r--r--src/lua/embed/mouse.lua.h11
-rw-r--r--src/lua/embed/path.lua15
-rw-r--r--src/lua/embed/path.lua.h21
13 files changed, 684 insertions, 0 deletions
diff --git a/src/lua/embed/boot.lua b/src/lua/embed/boot.lua
new file mode 100644
index 0000000..6f846ae
--- /dev/null
+++ b/src/lua/embed/boot.lua
@@ -0,0 +1,132 @@
+--[[
+ program entry
+]]
+
+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
+-------------------------------------------------
+jin._argv[2] = jin._argv[2] or '.'
+jin.filesystem.init()
+jin.filesystem.mount(jin._argv[2])
+
+-- config
+local conf = {}
+if jin.filesystem.exist("config.lua") then
+ conf = require "config"
+end
+conf.width = conf.width or 600
+conf.height = conf.height or 500
+conf.fps = conf.fps or 60
+conf.title = conf.title or ("jin v" .. jin.version())
+
+-- init video subsystem
+jin.graphics.init(conf.width,conf.height,conf.title)
+
+-- open debug mode, must after jin.graphics.init
+if jin._argv[3] == '-d' then
+ jin.debug.init()
+end
+
+function jin.core.run()
+ local now = jin.time.second()
+ local last = now
+ local fsec = 1/conf.fps
+ -- for loading resources
+ if jin.core.load then
+ jin.core.load()
+ end
+ local dt = 0
+ while(jin.core.running()) do
+ -- frame controle
+ last = now
+ now = jin.time.second()
+ if (now - last) < fsec then
+ jin.time.sleep(fsec - now + last)
+ end
+
+ -- handle events
+ for _, e in pairs(jin.event.poll()) do
+ if _onEvent then
+ _onEvent(e)
+ end
+ end
+
+ -- update
+ dt = now - last
+ if dt < fsec then
+ dt = fsec
+ end
+ if jin.core.onUpdate then
+ jin.core.onUpdate(dt)
+ end
+
+ -- bind to default render buffer
+ jin.graphics.bind()
+ jin.graphics.clear()
+ jin.graphics.color()
+ jin.graphics.study()
+
+ -- custom drawing
+ if jin.core.onDraw then
+ jin.core.onDraw()
+ end
+
+ -- render debug window
+ if jin.debug.status() then
+ jin.debug.render()
+ end
+
+ -- swap window buffer
+ jin.graphics.present()
+
+ end
+end
+
+local function onError(msg)
+ local tab = ' '
+ print("Error:\n" .. msg)
+ function jin.core.onEvent(e)
+ if e.type == 'quit' then
+ jin.core.quit()
+ end
+ end
+ local ww, wh = jin.graphics.size()
+ function jin.core.onDraw()
+ jin.graphics.write("Error: ", 10, 10, 30, 3, 30)
+ jin.graphics.write(msg, 10, 50)
+ end
+end
+
+if jin.filesystem.exist("main.lua") then
+ -- require main game script
+ xpcall(function() require"main" end, onError)
+ jin.core.run()
+else
+ -- no game
+ function jin.core.onEvent(e)
+ if e.type == 'quit' then
+ jin.core.quit()
+ end
+ end
+ function jin.core.onDraw()
+ jin.graphics.clear(111, 134, 125, 255)
+ local ww, wh = jin.graphics.size()
+ local fw, fh = jin.graphics.box("no game", 20, 1, 20)
+ jin.graphics.write("no game", ww /2 - fw / 2, wh * 2/3, 16, 1, 18)
+ end
+ jin.core.run()
+end
diff --git a/src/lua/embed/boot.lua.h b/src/lua/embed/boot.lua.h
new file mode 100644
index 0000000..e1b8b34
--- /dev/null
+++ b/src/lua/embed/boot.lua.h
@@ -0,0 +1,143 @@
+/* boot.lua */
+static const char boot_lua[] =
+{45,45,91,91,32,13,10,32,32,32,32,112,114,111,103,114,97,109,32,101,110,116,
+114,121,13,10,93,93,32,32,13,10,13,10,108,111,99,97,108,32,102,117,110,99,116,
+105,111,110,32,95,111,110,69,118,101,110,116,40,101,41,32,13,10,32,32,32,32,
+45,45,32,117,112,100,97,116,101,32,107,101,121,98,111,97,114,100,32,115,116,
+97,116,117,115,32,13,10,32,32,32,32,105,102,32,101,46,116,121,112,101,32,61,
+61,32,34,107,101,121,100,111,119,110,34,32,116,104,101,110,32,13,10,32,32,32,
+32,32,32,32,32,106,105,110,46,107,101,121,98,111,97,114,100,46,115,101,116,40,
+101,46,107,101,121,44,32,116,114,117,101,41,32,13,10,32,32,32,32,101,108,115,
+101,105,102,32,101,46,116,121,112,101,32,61,61,32,34,107,101,121,117,112,34,
+32,116,104,101,110,32,13,10,32,32,32,32,32,32,32,32,106,105,110,46,107,101,
+121,98,111,97,114,100,46,115,101,116,40,101,46,107,101,121,44,32,102,97,108,
+115,101,41,13,10,32,32,32,32,101,110,100,32,13,10,13,10,32,32,32,32,45,45,32,
+99,97,108,108,32,117,115,101,114,32,111,110,69,118,101,110,116,32,102,117,110,
+99,116,105,111,110,32,13,10,32,32,32,32,105,102,32,106,105,110,46,99,111,114,
+101,46,111,110,69,118,101,110,116,32,116,104,101,110,32,13,10,32,32,32,32,32,
+32,32,32,106,105,110,46,99,111,114,101,46,111,110,69,118,101,110,116,40,101,
+41,32,13,10,32,32,32,32,101,110,100,13,10,101,110,100,32,13,10,13,10,45,45,45,
+45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,
+45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,13,10,45,45,32,
+105,110,105,116,32,102,105,108,101,32,115,121,115,116,101,109,32,13,10,45,45,
+45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,
+45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,13,10,106,105,
+110,46,95,97,114,103,118,91,50,93,32,61,32,106,105,110,46,95,97,114,103,118,
+91,50,93,32,111,114,32,39,46,39,13,10,106,105,110,46,102,105,108,101,115,121,
+115,116,101,109,46,105,110,105,116,40,41,13,10,106,105,110,46,102,105,108,101,
+115,121,115,116,101,109,46,109,111,117,110,116,40,106,105,110,46,95,97,114,
+103,118,91,50,93,41,13,10,13,10,45,45,32,99,111,110,102,105,103,13,10,108,111,
+99,97,108,32,99,111,110,102,32,61,32,123,125,32,13,10,105,102,32,106,105,110,
+46,102,105,108,101,115,121,115,116,101,109,46,101,120,105,115,116,40,34,99,
+111,110,102,105,103,46,108,117,97,34,41,32,116,104,101,110,32,13,10,9,99,111,
+110,102,32,61,32,114,101,113,117,105,114,101,32,34,99,111,110,102,105,103,34,
+9,13,10,101,110,100,32,13,10,99,111,110,102,46,119,105,100,116,104,32,61,32,
+99,111,110,102,46,119,105,100,116,104,32,111,114,32,54,48,48,32,13,10,99,111,
+110,102,46,104,101,105,103,104,116,32,61,32,99,111,110,102,46,104,101,105,103,
+104,116,32,111,114,32,53,48,48,32,13,10,99,111,110,102,46,102,112,115,32,61,
+32,99,111,110,102,46,102,112,115,32,111,114,32,54,48,13,10,99,111,110,102,46,
+116,105,116,108,101,32,61,32,99,111,110,102,46,116,105,116,108,101,32,111,114,
+32,40,34,106,105,110,32,118,34,32,46,46,32,106,105,110,46,118,101,114,115,105,
+111,110,40,41,41,13,10,13,10,45,45,32,105,110,105,116,32,118,105,100,101,111,
+32,115,117,98,115,121,115,116,101,109,32,13,10,106,105,110,46,103,114,97,112,
+104,105,99,115,46,105,110,105,116,40,99,111,110,102,46,119,105,100,116,104,44,
+99,111,110,102,46,104,101,105,103,104,116,44,99,111,110,102,46,116,105,116,
+108,101,41,13,10,13,10,45,45,32,111,112,101,110,32,100,101,98,117,103,32,109,
+111,100,101,44,32,109,117,115,116,32,97,102,116,101,114,32,106,105,110,46,103,
+114,97,112,104,105,99,115,46,105,110,105,116,13,10,105,102,32,106,105,110,46,
+95,97,114,103,118,91,51,93,32,61,61,32,39,45,100,39,32,116,104,101,110,32,13,
+10,9,106,105,110,46,100,101,98,117,103,46,105,110,105,116,40,41,13,10,101,110,
+100,13,10,13,10,102,117,110,99,116,105,111,110,32,106,105,110,46,99,111,114,
+101,46,114,117,110,40,41,13,10,32,32,32,32,108,111,99,97,108,32,110,111,119,
+32,61,32,106,105,110,46,116,105,109,101,46,115,101,99,111,110,100,40,41,13,10,
+32,32,32,32,108,111,99,97,108,32,108,97,115,116,32,61,32,110,111,119,13,10,32,
+32,32,32,108,111,99,97,108,32,102,115,101,99,32,61,32,49,47,99,111,110,102,46,
+102,112,115,13,10,32,32,32,32,45,45,32,102,111,114,32,108,111,97,100,105,110,
+103,32,114,101,115,111,117,114,99,101,115,13,10,32,32,32,32,105,102,32,106,
+105,110,46,99,111,114,101,46,108,111,97,100,32,116,104,101,110,32,13,10,32,32,
+32,32,32,32,32,32,106,105,110,46,99,111,114,101,46,108,111,97,100,40,41,32,13,
+10,32,32,32,32,101,110,100,13,10,32,32,32,32,119,104,105,108,101,40,106,105,
+110,46,99,111,114,101,46,114,117,110,110,105,110,103,40,41,41,32,100,111,13,
+10,32,32,32,32,32,32,32,32,45,45,32,102,114,97,109,101,32,99,111,110,116,114,
+111,108,101,13,10,32,32,32,32,32,32,32,32,108,97,115,116,32,61,32,110,111,119,
+13,10,32,32,32,32,32,32,32,32,110,111,119,32,61,32,106,105,110,46,116,105,109,
+101,46,115,101,99,111,110,100,40,41,13,10,32,32,32,32,32,32,32,32,105,102,32,
+40,110,111,119,32,45,32,108,97,115,116,41,32,60,32,102,115,101,99,32,116,104,
+101,110,32,13,10,32,32,32,32,32,32,32,32,32,32,32,32,106,105,110,46,116,105,
+109,101,46,115,108,101,101,112,40,102,115,101,99,32,45,32,110,111,119,32,43,
+32,108,97,115,116,41,13,10,32,32,32,32,32,32,32,32,101,110,100,13,10,13,10,32,
+32,32,32,32,32,32,32,45,45,32,104,97,110,100,108,101,32,101,118,101,110,116,
+115,32,32,32,32,32,13,10,32,32,32,32,32,32,32,32,102,111,114,32,95,44,32,101,
+32,105,110,32,112,97,105,114,115,40,106,105,110,46,101,118,101,110,116,46,112,
+111,108,108,40,41,41,32,100,111,32,13,10,32,32,32,32,32,32,32,32,32,32,32,32,
+105,102,32,95,111,110,69,118,101,110,116,32,116,104,101,110,13,10,32,32,32,32,
+32,32,32,32,32,32,32,32,32,32,32,32,95,111,110,69,118,101,110,116,40,101,41,
+13,10,32,32,32,32,32,32,32,32,32,32,32,32,101,110,100,13,10,32,32,32,32,32,32,
+32,32,101,110,100,13,10,13,10,32,32,32,32,32,32,32,32,45,45,32,117,112,100,97,
+116,101,13,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,100,116,32,61,32,
+110,111,119,32,45,32,108,97,115,116,13,10,32,32,32,32,32,32,32,32,105,102,32,
+100,116,32,60,32,102,115,101,99,32,116,104,101,110,32,13,10,32,32,32,32,32,32,
+32,32,32,32,32,32,100,116,32,61,32,102,115,101,99,32,13,10,32,32,32,32,32,32,
+32,32,101,110,100,13,10,32,32,32,32,32,32,32,32,105,102,32,106,105,110,46,99,
+111,114,101,46,111,110,85,112,100,97,116,101,32,116,104,101,110,13,10,32,32,
+32,32,32,32,32,32,32,32,32,32,106,105,110,46,99,111,114,101,46,111,110,85,112,
+100,97,116,101,40,100,116,41,13,10,32,32,32,32,32,32,32,32,101,110,100,13,10,
+32,32,32,32,32,32,32,32,13,10,9,9,45,45,32,98,105,110,100,32,116,111,32,100,
+101,102,97,117,108,116,32,114,101,110,100,101,114,32,98,117,102,102,101,114,
+32,13,10,9,9,106,105,110,46,103,114,97,112,104,105,99,115,46,98,105,110,100,
+40,41,32,13,10,9,9,106,105,110,46,103,114,97,112,104,105,99,115,46,99,108,101,
+97,114,40,41,32,13,10,9,9,106,105,110,46,103,114,97,112,104,105,99,115,46,99,
+111,108,111,114,40,41,13,10,9,9,106,105,110,46,103,114,97,112,104,105,99,115,
+46,115,116,117,100,121,40,41,13,10,13,10,9,9,45,45,32,99,117,115,116,111,109,
+32,100,114,97,119,105,110,103,13,10,9,9,105,102,32,106,105,110,46,99,111,114,
+101,46,111,110,68,114,97,119,32,116,104,101,110,32,13,10,32,32,32,32,32,32,32,
+32,32,32,32,32,106,105,110,46,99,111,114,101,46,111,110,68,114,97,119,40,41,
+32,13,10,32,32,32,32,32,32,32,32,101,110,100,13,10,9,9,13,10,9,9,45,45,32,114,
+101,110,100,101,114,32,100,101,98,117,103,32,119,105,110,100,111,119,13,10,9,
+9,105,102,32,106,105,110,46,100,101,98,117,103,46,115,116,97,116,117,115,40,
+41,32,116,104,101,110,32,13,10,9,9,9,106,105,110,46,100,101,98,117,103,46,114,
+101,110,100,101,114,40,41,13,10,9,9,101,110,100,32,9,9,13,10,13,10,32,32,32,
+32,32,32,32,32,45,45,32,115,119,97,112,32,119,105,110,100,111,119,32,98,117,
+102,102,101,114,32,13,10,32,32,32,32,32,32,32,32,106,105,110,46,103,114,97,
+112,104,105,99,115,46,112,114,101,115,101,110,116,40,41,13,10,13,10,32,32,32,
+32,101,110,100,13,10,101,110,100,13,10,13,10,108,111,99,97,108,32,102,117,110,
+99,116,105,111,110,32,111,110,69,114,114,111,114,40,109,115,103,41,32,13,10,9,
+108,111,99,97,108,32,116,97,98,32,61,32,39,32,32,32,32,39,13,10,9,112,114,105,
+110,116,40,34,69,114,114,111,114,58,92,110,34,32,46,46,32,109,115,103,41,13,
+10,9,102,117,110,99,116,105,111,110,32,106,105,110,46,99,111,114,101,46,111,
+110,69,118,101,110,116,40,101,41,32,13,10,9,9,105,102,32,101,46,116,121,112,
+101,32,61,61,32,39,113,117,105,116,39,32,116,104,101,110,32,13,10,9,9,9,106,
+105,110,46,99,111,114,101,46,113,117,105,116,40,41,13,10,9,9,101,110,100,13,
+10,9,101,110,100,13,10,9,108,111,99,97,108,32,119,119,44,32,119,104,32,61,32,
+106,105,110,46,103,114,97,112,104,105,99,115,46,115,105,122,101,40,41,32,13,
+10,9,102,117,110,99,116,105,111,110,32,106,105,110,46,99,111,114,101,46,111,
+110,68,114,97,119,40,41,32,13,10,9,9,106,105,110,46,103,114,97,112,104,105,99,
+115,46,119,114,105,116,101,40,34,69,114,114,111,114,58,32,34,44,32,49,48,44,
+32,49,48,44,32,51,48,44,32,51,44,32,51,48,41,13,10,9,9,106,105,110,46,103,114,
+97,112,104,105,99,115,46,119,114,105,116,101,40,109,115,103,44,32,49,48,44,32,
+53,48,41,32,13,10,9,101,110,100,13,10,101,110,100,13,10,13,10,105,102,32,106,
+105,110,46,102,105,108,101,115,121,115,116,101,109,46,101,120,105,115,116,40,
+34,109,97,105,110,46,108,117,97,34,41,32,116,104,101,110,32,13,10,9,45,45,32,
+114,101,113,117,105,114,101,32,109,97,105,110,32,103,97,109,101,32,115,99,114,
+105,112,116,13,10,9,120,112,99,97,108,108,40,102,117,110,99,116,105,111,110,
+40,41,32,114,101,113,117,105,114,101,34,109,97,105,110,34,32,101,110,100,44,
+32,111,110,69,114,114,111,114,41,13,10,9,106,105,110,46,99,111,114,101,46,114,
+117,110,40,41,13,10,101,108,115,101,32,13,10,9,45,45,32,110,111,32,103,97,109,
+101,32,13,10,9,102,117,110,99,116,105,111,110,32,106,105,110,46,99,111,114,
+101,46,111,110,69,118,101,110,116,40,101,41,32,13,10,9,9,105,102,32,101,46,
+116,121,112,101,32,61,61,32,39,113,117,105,116,39,32,116,104,101,110,32,13,10,
+9,9,9,106,105,110,46,99,111,114,101,46,113,117,105,116,40,41,13,10,9,9,101,
+110,100,13,10,9,101,110,100,13,10,9,102,117,110,99,116,105,111,110,32,106,105,
+110,46,99,111,114,101,46,111,110,68,114,97,119,40,41,32,13,10,9,9,106,105,110,
+46,103,114,97,112,104,105,99,115,46,99,108,101,97,114,40,49,49,49,44,32,49,51,
+52,44,32,49,50,53,44,32,50,53,53,41,32,13,10,9,9,108,111,99,97,108,32,119,119,
+44,32,119,104,32,61,32,106,105,110,46,103,114,97,112,104,105,99,115,46,115,
+105,122,101,40,41,32,13,10,9,9,108,111,99,97,108,32,102,119,44,32,102,104,32,
+61,32,106,105,110,46,103,114,97,112,104,105,99,115,46,98,111,120,40,34,110,
+111,32,103,97,109,101,34,44,32,50,48,44,32,49,44,32,50,48,41,13,10,9,9,106,
+105,110,46,103,114,97,112,104,105,99,115,46,119,114,105,116,101,40,34,110,111,
+32,103,97,109,101,34,44,32,119,119,32,47,50,32,45,32,102,119,32,47,32,50,44,
+32,119,104,32,42,32,50,47,51,44,32,49,54,44,32,49,44,32,49,56,41,13,10,9,101,
+110,100,13,10,9,106,105,110,46,99,111,114,101,46,114,117,110,40,41,13,10,101,
+110,100,13,10};
+
diff --git a/src/lua/embed/debug.lua b/src/lua/embed/debug.lua
new file mode 100644
index 0000000..fbf0967
--- /dev/null
+++ b/src/lua/embed/debug.lua
@@ -0,0 +1,128 @@
+--[[
+ for debug purpose
+ +-------------------+
+ |debug msg old |
+ |... |
+ |... |
+ |... |
+ |debug msg new |
+ +-------------------+
+]]
+
+jin.debug = jin.debug or {}
+
+-- render panel
+local panel = nil
+
+local debug = false
+
+-- debug msg buffer
+local buffer = {}
+
+-- configure
+local bsize = 10
+local fsize = 15
+local lheight = 18
+local alpha = 220
+local margin = 10
+
+-- refresh buffer or not
+local refresh = true
+
+function jin.debug.init()
+ debug = true
+ panel = jin.graphics.Canvas(jin.graphics.size())
+end
+
+-- set buffer size
+function jin.debug.size(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
+
+ -- remove the first one (old msg)
+ if #buffer >= bsize then
+ table.remove(buffer, 1)
+ end
+
+ buffer[#buffer + 1] = msg
+ refresh = true
+end
+
+-- clear debug buffer
+function jin.debug.clear()
+ 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
+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
+end
+
+-- render to screen
+function jin.debug.render()
+ if not debug then return end
+
+ if refresh then
+
+ jin.graphics.bind(panel)
+
+ jin.graphics.clear(0, 0, 0, 0)
+
+ jin.graphics.study()
+
+ local ww, wh = jin.graphics.size()
+ local bgw, bgh = getBgQuad()
+ jin.graphics.color(0, 0, 0, alpha)
+ jin.graphics.rect("fill", 0, wh - bgh - margin, bgw + margin, bgh + margin)
+
+ jin.graphics.color()
+ local y = wh
+ for i = #buffer, 1, -1 do
+ local msg = buffer[i]
+ local h = getStrHeight(msg, lheight)
+ y = y - h
+ jin.graphics.write(msg, margin / 2, y - margin/ 2, fsize, 1, lheight)
+ end
+
+ jin.graphics.bind()
+
+ refresh = false
+ end
+
+ jin.graphics.color()
+ jin.graphics.draw(panel, 0, 0)
+end
+
+function jin.debug.status()
+ return debug
+end
diff --git a/src/lua/embed/debug.lua.h b/src/lua/embed/debug.lua.h
new file mode 100644
index 0000000..f3838a0
--- /dev/null
+++ b/src/lua/embed/debug.lua.h
@@ -0,0 +1,125 @@
+/* debug.lua */
+static const char debug_lua[] =
+{45,45,91,91,32,13,10,32,32,32,32,102,111,114,32,100,101,98,117,103,32,112,117,
+114,112,111,115,101,32,13,10,32,32,32,32,43,45,45,45,45,45,45,45,45,45,45,45,
+45,45,45,45,45,45,45,45,43,13,10,32,32,32,32,124,100,101,98,117,103,32,109,
+115,103,32,111,108,100,32,32,32,32,32,32,124,13,10,32,32,32,32,124,46,46,46,
+32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,124,13,10,32,32,32,32,124,46,
+46,46,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,124,13,10,32,32,32,32,
+124,46,46,46,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,124,13,10,32,32,
+32,32,124,100,101,98,117,103,32,109,115,103,32,110,101,119,32,32,32,32,32,32,
+124,13,10,32,32,32,32,43,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,
+45,45,43,13,10,93,93,32,13,10,13,10,106,105,110,46,100,101,98,117,103,32,61,
+32,106,105,110,46,100,101,98,117,103,32,111,114,32,123,125,32,13,10,13,10,45,
+45,32,114,101,110,100,101,114,32,112,97,110,101,108,32,13,10,108,111,99,97,
+108,32,112,97,110,101,108,32,61,32,110,105,108,32,13,10,13,10,108,111,99,97,
+108,32,100,101,98,117,103,32,61,32,102,97,108,115,101,13,10,13,10,45,45,32,
+100,101,98,117,103,32,109,115,103,32,98,117,102,102,101,114,32,13,10,108,111,
+99,97,108,32,98,117,102,102,101,114,32,61,32,123,125,32,13,10,13,10,45,45,32,
+99,111,110,102,105,103,117,114,101,32,13,10,108,111,99,97,108,32,98,115,105,
+122,101,32,32,32,61,32,49,48,13,10,108,111,99,97,108,32,102,115,105,122,101,
+32,32,32,61,32,49,53,13,10,108,111,99,97,108,32,108,104,101,105,103,104,116,
+32,61,32,49,56,13,10,108,111,99,97,108,32,97,108,112,104,97,32,32,32,61,32,50,
+50,48,13,10,108,111,99,97,108,32,109,97,114,103,105,110,32,32,61,32,49,48,13,
+10,13,10,45,45,32,114,101,102,114,101,115,104,32,98,117,102,102,101,114,32,
+111,114,32,110,111,116,32,13,10,108,111,99,97,108,32,114,101,102,114,101,115,
+104,32,61,32,116,114,117,101,32,13,10,13,10,102,117,110,99,116,105,111,110,32,
+106,105,110,46,100,101,98,117,103,46,105,110,105,116,40,41,13,10,32,32,32,32,
+100,101,98,117,103,32,61,32,116,114,117,101,13,10,9,112,97,110,101,108,32,61,
+32,106,105,110,46,103,114,97,112,104,105,99,115,46,67,97,110,118,97,115,40,
+106,105,110,46,103,114,97,112,104,105,99,115,46,115,105,122,101,40,41,41,32,
+13,10,101,110,100,13,10,13,10,45,45,32,115,101,116,32,98,117,102,102,101,114,
+32,115,105,122,101,32,13,10,102,117,110,99,116,105,111,110,32,106,105,110,46,
+100,101,98,117,103,46,115,105,122,101,40,99,41,13,10,9,98,115,105,122,101,32,
+61,32,99,13,10,101,110,100,32,13,10,13,10,102,117,110,99,116,105,111,110,32,
+106,105,110,46,100,101,98,117,103,46,112,114,105,110,116,40,109,115,103,41,13,
+10,9,105,102,32,110,111,116,32,100,101,98,117,103,32,116,104,101,110,32,114,
+101,116,117,114,110,32,101,110,100,32,13,10,13,10,9,109,115,103,32,61,32,116,
+111,115,116,114,105,110,103,40,109,115,103,41,13,10,9,108,111,99,97,108,32,
+116,112,32,61,32,116,121,112,101,40,109,115,103,41,13,10,9,105,102,32,116,112,
+32,126,61,32,34,115,116,114,105,110,103,34,32,97,110,100,32,116,112,32,126,61,
+32,34,110,117,109,98,101,114,34,32,116,104,101,110,32,13,10,9,9,109,115,103,
+32,61,32,115,116,114,105,110,103,46,102,111,114,109,97,116,40,34,112,114,105,
+110,116,32,102,97,105,108,101,100,44,32,101,120,112,101,99,116,32,115,116,114,
+105,110,103,32,111,114,32,110,117,109,98,101,114,32,98,117,116,32,103,101,116,
+32,97,32,37,115,34,44,32,116,112,41,13,10,9,101,110,100,13,10,9,13,10,32,32,
+32,32,45,45,32,114,101,109,111,118,101,32,116,104,101,32,102,105,114,115,116,
+32,111,110,101,32,40,111,108,100,32,109,115,103,41,13,10,9,105,102,32,35,98,
+117,102,102,101,114,32,62,61,32,98,115,105,122,101,32,116,104,101,110,32,13,
+10,9,9,116,97,98,108,101,46,114,101,109,111,118,101,40,98,117,102,102,101,114,
+44,32,49,41,13,10,9,101,110,100,32,13,10,32,32,32,32,13,10,32,32,32,32,98,117,
+102,102,101,114,91,35,98,117,102,102,101,114,32,43,32,49,93,32,61,32,109,115,
+103,13,10,32,32,32,32,114,101,102,114,101,115,104,32,61,32,116,114,117,101,13,
+10,101,110,100,13,10,13,10,45,45,32,99,108,101,97,114,32,100,101,98,117,103,
+32,98,117,102,102,101,114,32,13,10,102,117,110,99,116,105,111,110,32,106,105,
+110,46,100,101,98,117,103,46,99,108,101,97,114,40,41,13,10,9,98,117,102,102,
+101,114,32,61,32,123,125,32,13,10,101,110,100,13,10,13,10,108,111,99,97,108,
+32,102,117,110,99,116,105,111,110,32,103,101,116,83,116,114,72,101,105,103,
+104,116,40,115,116,114,44,32,108,104,101,105,103,104,116,41,32,13,10,9,108,
+111,99,97,108,32,104,32,61,32,108,104,101,105,103,104,116,13,10,9,105,102,32,
+35,115,116,114,32,61,61,32,48,32,116,104,101,110,32,13,10,9,9,104,32,61,32,48,
+13,10,9,101,110,100,32,13,10,9,102,111,114,32,105,32,61,32,49,44,32,35,115,
+116,114,32,100,111,32,13,10,9,9,108,111,99,97,108,32,99,32,61,32,115,116,114,
+105,110,103,46,115,117,98,40,115,116,114,44,32,105,44,32,105,41,13,10,9,9,105,
+102,32,99,32,61,61,32,39,92,110,39,32,116,104,101,110,32,13,10,9,9,9,104,32,
+61,32,104,32,43,32,108,104,101,105,103,104,116,13,10,9,9,101,110,100,32,13,10,
+9,101,110,100,32,13,10,9,114,101,116,117,114,110,32,104,32,13,10,101,110,100,
+13,10,13,10,108,111,99,97,108,32,32,102,117,110,99,116,105,111,110,32,103,101,
+116,66,103,81,117,97,100,40,41,32,13,10,9,108,111,99,97,108,32,119,105,100,
+116,104,44,32,104,101,105,103,104,116,32,61,32,48,44,32,48,32,9,13,10,9,102,
+111,114,32,105,32,61,32,49,44,32,35,98,117,102,102,101,114,32,100,111,13,10,9,
+9,108,111,99,97,108,32,119,44,32,104,32,61,32,106,105,110,46,103,114,97,112,
+104,105,99,115,46,98,111,120,40,32,98,117,102,102,101,114,91,105,93,44,32,102,
+115,105,122,101,44,32,49,44,32,108,104,101,105,103,104,116,41,13,10,9,9,104,
+101,105,103,104,116,32,61,32,104,101,105,103,104,116,32,43,32,104,32,13,10,9,
+9,105,102,32,119,105,100,116,104,32,60,32,119,32,116,104,101,110,13,10,9,9,9,
+119,105,100,116,104,32,61,32,119,32,13,10,9,9,101,110,100,32,13,10,9,101,110,
+100,9,13,10,9,114,101,116,117,114,110,32,119,105,100,116,104,44,32,104,101,
+105,103,104,116,13,10,101,110,100,32,13,10,13,10,45,45,32,114,101,110,100,101,
+114,32,116,111,32,115,99,114,101,101,110,13,10,102,117,110,99,116,105,111,110,
+32,106,105,110,46,100,101,98,117,103,46,114,101,110,100,101,114,40,41,32,13,
+10,32,32,32,32,105,102,32,110,111,116,32,100,101,98,117,103,32,116,104,101,
+110,32,114,101,116,117,114,110,32,101,110,100,13,10,32,32,32,32,13,10,32,32,
+32,32,105,102,32,114,101,102,114,101,115,104,32,116,104,101,110,32,13,10,32,
+32,32,32,32,32,32,13,10,32,32,32,32,32,32,32,32,106,105,110,46,103,114,97,112,
+104,105,99,115,46,98,105,110,100,40,112,97,110,101,108,41,13,10,13,10,32,32,
+32,32,32,32,32,32,32,32,32,32,106,105,110,46,103,114,97,112,104,105,99,115,46,
+99,108,101,97,114,40,48,44,32,48,44,32,48,44,32,48,41,13,10,32,32,32,32,32,32,
+32,32,32,32,32,32,13,10,32,32,32,32,32,32,32,32,32,32,32,32,106,105,110,46,
+103,114,97,112,104,105,99,115,46,115,116,117,100,121,40,41,13,10,32,32,32,32,
+32,32,32,32,32,32,32,32,13,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,
+97,108,32,119,119,44,32,119,104,32,61,32,106,105,110,46,103,114,97,112,104,
+105,99,115,46,115,105,122,101,40,41,13,10,32,32,32,32,32,32,32,32,32,32,32,32,
+108,111,99,97,108,32,98,103,119,44,32,98,103,104,32,61,32,103,101,116,66,103,
+81,117,97,100,40,41,13,10,32,32,32,32,32,32,32,32,32,32,32,32,106,105,110,46,
+103,114,97,112,104,105,99,115,46,99,111,108,111,114,40,48,44,32,48,44,32,48,
+44,32,97,108,112,104,97,41,13,10,32,32,32,32,32,32,32,32,32,32,32,32,106,105,
+110,46,103,114,97,112,104,105,99,115,46,114,101,99,116,40,34,102,105,108,108,
+34,44,32,48,44,32,119,104,32,45,32,98,103,104,32,45,32,109,97,114,103,105,110,
+44,32,98,103,119,32,43,32,109,97,114,103,105,110,44,32,98,103,104,32,43,32,
+109,97,114,103,105,110,41,13,10,32,32,32,32,32,32,32,32,32,32,32,32,13,10,32,
+32,32,32,32,32,32,32,32,32,32,32,106,105,110,46,103,114,97,112,104,105,99,115,
+46,99,111,108,111,114,40,41,13,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,
+99,97,108,32,121,32,61,32,119,104,32,13,10,32,32,32,32,32,32,32,32,32,32,32,
+32,102,111,114,32,105,32,61,32,35,98,117,102,102,101,114,44,32,49,44,32,45,49,
+32,100,111,13,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,
+97,108,32,109,115,103,32,61,32,98,117,102,102,101,114,91,105,93,32,13,10,32,
+32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,104,32,61,
+32,103,101,116,83,116,114,72,101,105,103,104,116,40,109,115,103,44,32,108,104,
+101,105,103,104,116,41,13,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
+121,32,61,32,121,32,45,32,104,32,13,10,32,32,32,32,32,32,32,32,32,32,32,32,32,
+32,32,32,106,105,110,46,103,114,97,112,104,105,99,115,46,119,114,105,116,101,
+40,109,115,103,44,32,109,97,114,103,105,110,32,47,32,50,44,32,121,32,45,32,
+109,97,114,103,105,110,47,32,50,44,32,102,115,105,122,101,44,32,49,44,32,108,
+104,101,105,103,104,116,41,32,13,10,32,32,32,32,32,32,32,32,32,32,32,32,101,
+110,100,13,10,9,13,10,32,32,32,32,32,32,32,32,106,105,110,46,103,114,97,112,
+104,105,99,115,46,98,105,110,100,40,41,13,10,32,32,32,32,13,10,32,32,32,32,32,
+32,32,32,114,101,102,114,101,115,104,32,61,32,102,97,108,115,101,13,10,32,32,
+32,32,101,110,100,32,13,10,32,32,32,32,13,10,32,32,32,32,106,105,110,46,103,
+114,97,112,104,105,99,115,46,99,111,108,111,114,40,41,13,10,32,32,32,32,106,
+105,110,46,103,114,97,112,104,105,99,115,46,100,114,97,119,40,112,97,110,101,
+108,44,32,48,44,32,48,41,13,10,101,110,100,13,10,13,10,102,117,110,99,116,105,
+111,110,32,106,105,110,46,100,101,98,117,103,46,115,116,97,116,117,115,40,41,
+32,13,10,9,114,101,116,117,114,110,32,100,101,98,117,103,32,13,10,101,110,100,
+13,10};
+
diff --git a/src/lua/embed/embed.h b/src/lua/embed/embed.h
new file mode 100644
index 0000000..685355f
--- /dev/null
+++ b/src/lua/embed/embed.h
@@ -0,0 +1,51 @@
+#ifndef __JIN_LUA_EMBED_H
+#define __JIN_LUA_EMBED_H
+#include <cstring>
+
+namespace jin
+{
+namespace embed
+{
+
+ /**
+ * embed lua script to context.
+ */
+#define embed(L, script, name) \
+ if(luaL_loadbuffer(L, script, strlen(script), name) == 0)\
+ lua_call(L, 0, 0);
+
+ /**
+ * embed structure.
+ */
+ struct jin_Embed
+ {
+ const char* fname, *source;
+ };
+
+ static void boot(lua_State* L)
+ {
+ // embed scripts
+ #include "graphics.lua.h" // graphics
+ #include "keyboard.lua.h" // keyboard
+ #include "mouse.lua.h" // mouse
+ #include "debug.lua.h" // debug
+ #include "boot.lua.h" // boot
+
+ // embed scripts
+ const jin_Embed scripts[] = {
+ { "graphics.lua", graphics_lua },
+ { "keyboard.lua", keyboard_lua },
+ { "mouse.lua", mouse_lua },
+ { "debug.lua", debug_lua},
+ { "boot.lua", boot_lua },
+ { 0, 0 }
+ };
+
+ // load all emebd lua scripts
+ for (int i = 0; scripts[i].fname; i++)
+ embed(L, scripts[i].source, scripts[i].fname);
+ }
+}
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/embed/graphics.lua b/src/lua/embed/graphics.lua
new file mode 100644
index 0000000..03a891d
--- /dev/null
+++ b/src/lua/embed/graphics.lua
@@ -0,0 +1,6 @@
+-----------------
+-- jin.graphics
+-----------------
+
+jin.graphics = jin.graphics or {}
+
diff --git a/src/lua/embed/graphics.lua.h b/src/lua/embed/graphics.lua.h
new file mode 100644
index 0000000..0e10e97
--- /dev/null
+++ b/src/lua/embed/graphics.lua.h
@@ -0,0 +1,8 @@
+/* graphics.lua */
+static const char graphics_lua[] =
+{45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,13,10,45,45,32,106,105,110,
+46,103,114,97,112,104,105,99,115,32,13,10,45,45,45,45,45,45,45,45,45,45,45,45,
+45,45,45,45,45,13,10,13,10,106,105,110,46,103,114,97,112,104,105,99,115,32,61,
+32,106,105,110,46,103,114,97,112,104,105,99,115,32,111,114,32,123,125,32,13,
+10,13,10};
+
diff --git a/src/lua/embed/keyboard.lua b/src/lua/embed/keyboard.lua
new file mode 100644
index 0000000..08214f8
--- /dev/null
+++ b/src/lua/embed/keyboard.lua
@@ -0,0 +1,16 @@
+--[[
+ jin.keyboard extension
+]]
+
+jin.keyboard = jin.keyboard or {}
+
+local keys = {}
+
+function jin.keyboard.isDown(k)
+ return keys[k]
+end
+
+function jin.keyboard.set(k, status)
+ keys[k] = status
+end
+
diff --git a/src/lua/embed/keyboard.lua.h b/src/lua/embed/keyboard.lua.h
new file mode 100644
index 0000000..037c255
--- /dev/null
+++ b/src/lua/embed/keyboard.lua.h
@@ -0,0 +1,13 @@
+
+static const char keyboard_lua[] =
+{ 45,45,91,91,32,13,10,9,107,101,121,98,111,97,114,100,32,101,120,116,101,110,
+ 115,105,111,110,32,13,10,93,93,32,13,10,13,10,106,105,110,46,107,101,121,98,
+ 111,97,114,100,32,61,32,106,105,110,46,107,101,121,98,111,97,114,100,32,111,
+ 114,32,123,125,32,13,10,13,10,108,111,99,97,108,32,107,101,121,115,32,61,32,
+ 123,125,32,13,10,13,10,102,117,110,99,116,105,111,110,32,106,105,110,46,107,
+ 101,121,98,111,97,114,100,46,105,115,68,111,119,110,40,107,41,32,13,10,32,32,
+ 32,32,114,101,116,117,114,110,32,107,101,121,115,91,107,93,13,10,101,110,100,
+ 32,32,13,10,13,10,102,117,110,99,116,105,111,110,32,106,105,110,46,107,101,
+ 121,98,111,97,114,100,46,115,101,116,40,107,44,32,115,116,97,116,117,115,41,
+ 32,13,10,9,107,101,121,115,91,107,93,32,61,32,115,116,97,116,117,115,32,13,10,
+ 101,110,100,32,13,10 };
diff --git a/src/lua/embed/mouse.lua b/src/lua/embed/mouse.lua
new file mode 100644
index 0000000..9dcd472
--- /dev/null
+++ b/src/lua/embed/mouse.lua
@@ -0,0 +1,15 @@
+--[[
+ jin.mouse extension
+]]
+
+jin.mouse = jin.mouse or {}
+
+local button = {}
+
+function jin.mouse.isDown(btn)
+ return button[btn]
+end
+
+function jin.mouse.set(btn, status)
+ button[btn] = status
+end
diff --git a/src/lua/embed/mouse.lua.h b/src/lua/embed/mouse.lua.h
new file mode 100644
index 0000000..eb5a3ad
--- /dev/null
+++ b/src/lua/embed/mouse.lua.h
@@ -0,0 +1,11 @@
+static const char mouse_lua[] =
+{45,45,91,91,32,13,10,9,109,111,117,115,101,32,101,120,116,101,110,115,105,111,
+110,13,10,93,93,32,13,10,13,10,106,105,110,46,109,111,117,115,101,32,61,32,
+106,105,110,46,109,111,117,115,101,32,111,114,32,123,125,32,13,10,13,10,108,
+111,99,97,108,32,98,117,116,116,111,110,32,61,32,123,125,32,13,10,13,10,102,
+117,110,99,116,105,111,110,32,106,105,110,46,109,111,117,115,101,46,105,115,
+68,111,119,110,40,98,116,110,41,32,13,10,9,114,101,116,117,114,110,32,98,117,
+116,116,111,110,91,98,116,110,93,13,10,101,110,100,32,13,10,13,10,102,117,110,
+99,116,105,111,110,32,106,105,110,46,109,111,117,115,101,46,115,101,116,40,98,
+116,110,44,32,115,116,97,116,117,115,41,32,13,10,9,98,117,116,116,111,110,91,
+98,116,110,93,32,61,32,115,116,97,116,117,115,13,10,101,110,100,32,13,10};
diff --git a/src/lua/embed/path.lua b/src/lua/embed/path.lua
new file mode 100644
index 0000000..5b99dd2
--- /dev/null
+++ b/src/lua/embed/path.lua
@@ -0,0 +1,15 @@
+--[[
+ jin.path extension
+]]
+
+jin.path = jin.path or {}
+
+-- game root directory
+jin._root = nil
+
+-- return full path of a given path
+function jin.path.full(path)
+ local root = jin._dir .. '/' .. jin._argv[2]
+ return root .. '/' .. path
+end
+
diff --git a/src/lua/embed/path.lua.h b/src/lua/embed/path.lua.h
new file mode 100644
index 0000000..8a2968a
--- /dev/null
+++ b/src/lua/embed/path.lua.h
@@ -0,0 +1,21 @@
+/* path.lua */
+static const char path_lua[] =
+{45,45,91,91,32,13,10,32,32,32,32,106,105,110,46,112,97,116,104,32,101,120,116,
+101,110,115,105,111,110,13,10,93,93,32,13,10,13,10,106,105,110,46,112,97,116,
+104,32,61,32,106,105,110,46,112,97,116,104,32,111,114,32,123,125,32,13,10,13,
+10,45,45,32,103,97,109,101,32,114,111,111,116,32,100,105,114,101,99,116,111,
+114,121,32,13,10,106,105,110,46,95,114,111,111,116,32,61,32,110,105,108,32,13,
+10,13,10,108,111,99,97,108,32,102,117,110,99,116,105,111,110,32,105,115,102,
+117,108,108,40,112,97,116,104,41,32,13,10,32,32,32,32,13,10,101,110,100,32,13,
+10,13,10,45,45,32,109,101,114,103,101,32,115,117,98,32,112,97,116,104,32,105,
+110,116,111,32,111,110,101,32,13,10,108,111,99,97,108,32,102,117,110,99,116,
+105,111,110,32,109,101,114,103,101,40,46,46,46,41,32,13,10,32,32,32,32,13,10,
+101,110,100,32,13,10,13,10,45,45,32,114,101,116,117,114,110,32,102,117,108,
+108,32,112,97,116,104,32,111,102,32,97,32,103,105,118,101,110,32,112,97,116,
+104,32,13,10,102,117,110,99,116,105,111,110,32,106,105,110,46,112,97,116,104,
+46,102,117,108,108,40,112,97,116,104,41,13,10,32,32,32,32,108,111,99,97,108,
+32,114,111,111,116,32,61,32,106,105,110,46,95,100,105,114,32,46,46,32,39,47,
+39,32,46,46,32,106,105,110,46,95,97,114,103,118,91,50,93,13,10,32,32,32,32,
+114,101,116,117,114,110,32,114,111,111,116,32,46,46,32,39,47,39,32,46,46,32,
+112,97,116,104,32,13,10,101,110,100,13,10,13,10};
+