local b3b71 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
local r3b71 = function(i, f)
return function()
local c = f()
b3b71[i] = function() return c end
return c
end
end
local math = ((function() local x, y = pcall(require, 'math'); return x and y end)()) or _G.math
local function m3b71()
local version = b3b71[1]('source_version')
local util_decorator = b3b71[2]('source_shared_functional_decorator')
local tree = b3b71[3]('source_shared_engine_tree')
local loadcore = b3b71[4]('source_shared_engine_loadcore')
local loadgame = b3b71[5]('source_shared_engine_loadgame')
local engine_draw_fps = b3b71[6]('source_engine_api_draw_fps')
local engine_draw_poly = b3b71[7]('source_engine_api_draw_poly')
local engine_draw_text = b3b71[8]('source_engine_api_draw_text')
local engine_draw_ui = b3b71[9]('source_engine_api_draw_ui')
local engine_draw_img = b3b71[10]('source_engine_api_draw_image')
local engine_array = b3b71[11]('source_engine_api_data_array')
local engine_encoder = b3b71[12]('source_engine_api_data_encoder')
local engine_hash = b3b71[13]('source_engine_api_data_hash')
local engine_i18n = b3b71[14]('source_engine_api_data_i18n')
local engine_log = b3b71[15]('source_engine_api_debug_log')
local engine_http = b3b71[16]('source_engine_api_io_http')
local engine_media = b3b71[17]('source_engine_api_io_media')
local engine_storage = b3b71[18]('source_engine_api_io_storage')
local engine_raw_bus = b3b71[19]('source_engine_api_raw_bus')
local engine_raw_memory = b3b71[20]('source_engine_api_raw_memory')
local engine_raw_node = b3b71[21]('source_engine_api_raw_node')
local engine_env = b3b71[22]('source_engine_api_system_getenv')
local engine_color = b3b71[23]('source_engine_api_system_color')
local engine_game = b3b71[24]('source_engine_api_system_app')
local engine_key = b3b71[25]('source_engine_api_system_key')
local engine_math = b3b71[26]('source_engine_api_math_basic')
local engine_math_clib = b3b71[27]('source_engine_api_math_clib')
local engine_math_random = b3b71[28]('source_engine_api_math_random')
local callback_http = b3b71[29]('source_engine_protocol_http_callback')
local application_default = b3b71[30]('source_shared_var_object_root')
local std = b3b71[31]('source_shared_var_object_std')
local application = application_default
local engine = {
current = application_default,
root = application_default,
offset_x = 0,
offset_y = 0
}
local cfg_system = {
exit = native_system_exit,
reset = native_system_reset,
title = native_system_title,
get_fps = native_system_get_fps,
get_secret = native_system_get_secret,
get_language = native_system_get_language
}
local cfg_media = {
bootstrap=native_media_bootstrap,
position=native_media_position,
resize=native_media_resize,
resume=native_media_resume,
source=native_media_source,
pause=native_media_pause,
play=native_media_play,
stop=native_media_stop
}
local cfg_image = {
load = native_image_load,
draw = native_image_draw,
exists = native_image_exists,
mensure = native_image_mensure,
unload = native_image_unload,
unload_all = native_image_unload_all
}
local cfg_poly = {
repeats = {
native_cfg_poly_repeat_0 or false,
native_cfg_poly_repeat_1 or false,
native_cfg_poly_repeat_2 or false
},
triangle = native_draw_triangle,
poly2 = native_draw_poly2,
poly = native_draw_poly,
line = native_draw_line
}
local cfg_http = {
install = native_http_install,
handler = native_http_handler,
has_ssl = native_http_has_ssl,
force = native_http_force_protocol
}
local cfg_log = {
fatal = native_log_fatal,
error = native_log_error,
warn = native_log_warn,
info = native_log_info,
debug = native_log_debug
}
local cfg_base64 = {
decode = native_base64_decode,
encode = native_base64_encode
}
local cfg_json = {
decode = native_json_decode,
encode = native_json_encode
}
local cfg_xml = {
decode = native_xml_decode,
encode = native_xml_encode
}
local cfg_text = {
is_tui = native_text_is_tui,
font_previous = native_text_font_previous
}
local cfg_storage = {
install = native_storage_install and function() native_storage_install() end,
get = native_storage_get,
set = native_storage_set
}
local cfg_env = {
get_env = native_system_get_env
}
local cfg_key = {
has_media = native_keyboard_has_media,
}
local function clear(tint)
local x, y = engine.offset_x, engine.offset_y
local width, height = engine.current.data.width, engine.current.data.height
native_draw_clear(tint, x, y, width, height)
end
function native_callback_loop(dt)
std.milis = std.milis + dt
std.delta = dt
std.bus.emit('loop')
end
function native_callback_draw()
native_draw_start()
std.bus.emit('draw')
native_draw_flush()
end
function native_callback_resize(width, height)
engine.root.data.width = width
engine.root.data.height = height
std.app.width = width
std.app.height = height
std.bus.emit('resize', width, height)
end
function native_callback_keyboard(key, value)
std.bus.emit('rkey', key, value)
end
function native_callback_http(id, key, data)
return callback_http.func(engine['http'][id], key, data, std)
end
function native_callback_init(width, height, game_lua)
application = loadgame.script(game_lua, application_default)
if application then
application.data.width = width
application.data.height = height
std.app.width = width
std.app.height = height
end
std.draw.color=native_draw_color
std.draw.clear=clear
std.draw.rect2=util_decorator.offset_xy2(engine, native_draw_rect2 or native_draw_rect)
std.draw.rect=util_decorator.offset_xy2(engine, native_draw_rect)
std.draw.line=util_decorator.offset_xyxy1(engine, native_draw_line)
std.text.print = util_decorator.offset_xy1(engine, native_text_print)
std.text.mensure=native_text_mensure
std.text.font_size=native_text_font_size
std.text.font_name=native_text_font_name
std.text.font_default=native_text_font_default
std.text.mensure_width=function(v) return select(1, native_text_mensure(v)) end
std.text.mensure_height=function(v) return select(2, native_text_mensure(v)) end
engine.handler = function(msg) 
if select(2, pcall(engine.root.callbacks.error or function() end, engine.root.data, std, tostring(msg))) == true then
(native_system_exit or native_system_fatal or function() end)()
end
end
loadcore.setup(std, application, engine)
:package('@bus', engine_raw_bus)
:package('@node', engine_raw_node)
:package('@memory', engine_raw_memory)
:package('@game', engine_game, cfg_system)
:package('@math', engine_math)
:package('@array', engine_array)
:package('@key', engine_key, cfg_key)
:package('@draw.ui', engine_draw_ui)
:package('@draw.img', engine_draw_img, cfg_image)
:package('@draw.fps', engine_draw_fps)
:package('@draw.text', engine_draw_text, cfg_text)
:package('@draw.poly', engine_draw_poly, cfg_poly)
:package('@color', engine_color)
:package('@log', engine_log, cfg_log)
:package('@env', engine_env, cfg_env)        
:package('math', engine_math_clib)
:package('math.random', engine_math_random)
:package('http', engine_http, cfg_http)
:package('base64', engine_encoder, cfg_base64)
:package('json', engine_encoder, cfg_json)
:package('xml', engine_encoder, cfg_xml)
:package('i18n', engine_i18n, cfg_system)
:package('media.video', engine_media, cfg_media)
:package('media.music', engine_media, cfg_media)
:package('mock.video', engine_media)
:package('mock.music', engine_media)
:package('storage', engine_storage, cfg_storage)
:package('hash', engine_hash, cfg_system)
:run()
application.data.width, std.app.width = width, width
application.data.height, std.app.height = height, height
std.app.title(application.meta.title..' - '..application.meta.version)
engine.dom = tree.node_begin(application, std.app.width, std.app.height)
engine.root, engine.current = application, application
std.bus.emit_next('load')
std.bus.emit_next('init')
end
local P = {
meta={
title='gly-engine',
author='RodrigoDornelles',
description='native core',
version=version
}
}
return P
end
b3b71[1] = r3b71(1, function()
return '0.3.13'
end)
b3b71[2] = r3b71(2, function()
local function decorator_prefix3(zig, zag, zom, func)
return function (a, b, c, d, e, f)
return func(zig, zag, zom, a, b, c, d, e, f)
end
end
local function decorator_prefix2(zig, zag, func)
return function (a, b, c, d, e, f)
return func(zig, zag, a, b, c, d, e, f)
end
end
local function decorator_prefix1(zig, func)
return function (a, b, c, d, e, f)
return func(zig, a, b, c, d, e, f)
end
end
local function decorator_offset_xy2(object, func)
return function(a, b, c, d, e, f)
local x = object.offset_x + (b or 0)
local y = object.offset_y + (c or 0)
return func(a, x, y, d, e, f)
end
end
local function decorator_offset_xyxy1(object, func)
return function(a, b, c, d, e, f)
local x1 = object.offset_x + a
local y1 = object.offset_y + b
local x2 = object.offset_x + c
local y2 = object.offset_y + d
return func(x1, y1, x2, y2, e, f)
end
end
local function decorator_offset_xy1(object, func)
return function(a, b, c, d, e, f)
local x = object.offset_x + a
local y = object.offset_y + b
return func(x, y, c, d, e, f)
end
end
local function table_prefix1(prefix, fn_table)
local new_table = {}
for name, fn in pairs(fn_table) do
new_table[name] = decorator_prefix1(prefix, fn)
end
return new_table
end
local P = {
offset_xy1 = decorator_offset_xy1,
offset_xy2 = decorator_offset_xy2,
offset_xyxy1 = decorator_offset_xyxy1,
prefix3 = decorator_prefix3,
prefix2 = decorator_prefix2,
prefix1 = decorator_prefix1,
prefix1_t = table_prefix1
}
return P
end)
b3b71[3] = r3b71(3, function()
local function cells(node)
local cfg = node.config
local dat = node.data
if cfg.type == 'grid' then
local cols, rows = cfg.cols, cfg.rows
local w = dat.width / rows
local h = dat.height / cols
return w, h
end
return dat.width, dat.height
end
local function walk(node, fn)
fn(node)
if node.childs then
for _, child in ipairs(node.childs) do
walk(child, fn)
end
end
end
local function stylesheet(self, name, options)
local css = self.stylesheet_dict[name] or {}
local exe = self.stylesheet_func[name]
if options then
self.flag_reposition = true
css.left = options.left or options.margin or nil
css.right = options.right or options.margin or nil
css.top = options.top or options.margin or nil
css.bottom = options.bottom or options.margin or nil
css.height = options.height or nil
css.width = options.width or nil
end
if not exe then
exe = function(x, y, width, height)
local css_left, has_left = css.left or 0, css.left ~= nil
local css_right, has_right = css.right or 0, css.left ~= nil
local css_top, has_top = css.top or 0, css.top ~= nil
local css_bottom, has_bottom = css.bottom or 0, css.bottom ~= nil
local css_width, css_height = css.width, css.height
if css_width then
if (has_left and has_right) or (not has_left and not has_right) then                    
local free = width - css_left - css_right - css_width
x = x + css_left + free * (1/2)
width = css_width
elseif not has_left and has_right then
x = x + width - css_right - css_width
width = css_width
else
x = x + (css_left or 0)
width = css_width
end
else
if has_left then 
x = x + css_left
width = width - css_left
end
if has_right then
width = width - css_right
end
end
if css_height then
if (has_top and has_bottom) or (not has_top and not has_bottom) then
local free = height - css_top - css_bottom - css_height
y = y + css_top + free * (1/2)
height = css_height
elseif not has_top and has_bottom then
y = y + height - css_bottom - css_height
height = css_height
else
y = y + (css_top or 0)
height = css_height
end
else
if has_top then
y = y + css_top
height = height - css_top
end
if has_bottom then 
height = height - css_bottom
end
end
return x, y, width, height
end
end
self.stylesheet_dict[name] = css
self.stylesheet_func[name] = exe
return exe
end
local function css_add(self, func, node)
local styles, found, index = node.config.css, false, 1 
while index <= #styles do
if styles[index] == func then found = true end
index = index + 1
end
if not found then
styles[#styles + 1] = func
end
self.flag_reposition = true
end
local function css_del(self, func, node)
local styles, src, dst = node.config.css, 1, 1
while src <= #styles do
local item = styles[src]
if item ~= func then
styles[dst] = item
dst = dst + 1
end
src = src + 1
end
while dst <= #styles do
styles[dst] = nil
dst = dst + 1
end
self.flag_reposition = true
end
local function node_begin(node, width, height)
local self = {}
self.width = width
self.height = height
self.root = node
self.node_list = { node }
self.stylesheet_dict = {}
self.stylesheet_func = {}
self.flag_reparent = false
self.flag_reposition = true
self.flag_to_delete = {}
node.config.css = {}
node.config.type = 'root'
return self
end
local function node_add(self, node, options)
local parent = options.parent
local dat = node.data
local cfg = node.config
if not parent.childs then
parent.childs = {}
end
if not cfg.parent then
self.node_list[#self.node_list + 1] = node
end
dat.width, dat.height = cells(parent)
parent.childs[#parent.childs + 1] = node
cfg.css = {}
cfg.pause_key = {}
cfg.pause_all = false
cfg.parent = parent
cfg.size = options.size or 1
cfg.after = options.after or 0
cfg.offset = options.offset or 0
self.flag_relist = false
self.flag_reparent = true
self.flag_reposition = true
end
local function node_del(self, node_root)
walk(node_root, function(node)
node.data = {}
node.config.css = {}
node.config.parent = nil
end)
self.flag_relist = true
self.flag_reparent = true
self.flag_reposition = true
end
local function node_pause(self, node_root, key)
walk(node_root, function(node)
if key then
node.config.pause_key[key] = true
else
node.config.pause_key = {}
node.config.pause_all = true
end
end)
end
local function node_resume(self, node_root, key)
local parent_config = node_root.config.parent and node_root.config.parent.config
local parent_is_paused = parent_config and parent_config.pause_all
if parent_is_paused then return end
walk(node_root, function(node)
if key then
node.config.pause_key[key] = false
else
node.config.pause_key = {}
node.config.pause_all = false
end
end)
end
local function resize(self, width, height)
self.width = width
self.height = height
self.flag_reposition = true
end
local function rebuild_list(self)
local index, new_node_list = 2, { self.root }
while index <= #self.node_list do
if self.node_list[index].config.parent then
new_node_list[#new_node_list + 1] = self.node_list[index]
end
index = index + 1
end
self.node_list = new_node_list
end
local function rebuild_tree_from_parents(self)
local index = 1
while index <= #self.node_list do
local node = self.node_list[index]
node.childs = {}
index = index + 1
end
index = 1
while index <= #self.node_list do
local node = self.node_list[index]
local parent = node.config.parent
if parent then
parent.childs[#parent.childs + 1] = node
end
index = index + 1
end
end
local function dom(node, parent_x, parent_y, parent_w, parent_h)
local cfg = node.config
local dat = node.data
cfg.offset_x = parent_x
cfg.offset_y = parent_y
dat.width = parent_w
dat.height = parent_h
if cfg.type == "grid" then
local cols, rows, dir = cfg.cols, cfg.rows, cfg.dir
local cell_w, cell_h = cells(node)
local x, y = 0, 0
for _, child in ipairs(node.childs) do
local cc = child.config
local offset, after, size = cc.offset, cc.after, cc.size
local cx = parent_x + cell_w * (((dir == 0) and offset or 0) + x)
local cy = parent_y + cell_h * (((dir == 1) and offset or 0) + y)
local w = (dir == 0) and (size * cell_w) or cell_w
local h = (dir == 1) and (size * cell_h) or cell_h
for _, css in ipairs(cc.css) do
cx, cy, w, h = css(cx, cy, w, h)
end
dom(child, cx, cy, w, h)
if dir == 1 then
y = y + size + offset + after
if y >= cols then y, x = 0, x + 1 end
else
x = x + size + offset + after
if x >= rows then x, y = 0, y + 1 end
end
end
elseif node.childs then
for _, child in ipairs(node.childs) do
local x, y, w, h = parent_x, parent_y, parent_w, parent_h
for _, css in ipairs(child.config.css) do
x, y, w, h = css(x, y, w, h)
end
dom(child, x, y, w, h)
end
end
end
local function bus(self, key, handler_func)
if self.flag_relist then
rebuild_list(self)
self.flag_relist = false
end
if self.flag_reparent then
rebuild_tree_from_parents(self)
self.flag_reparent = false
end
if self.flag_reposition then
dom(self.root, 0, 0, self.width, self.height)
self.flag_reposition = false
end
do
local index = 1
while index <= #self.node_list do
local node = self.node_list[index]
local ignore = index ~= 1
if ignore then
local is_pause_global = node.config.pause_all
local is_pause_local = node.config.pause_key[key]
local is_resume_local = is_pause_local == false
ignore = is_pause_local or (is_pause_global and not is_resume_local)
end
if not ignore then
handler_func(node)
end
index = index + 1
end
end
end
local P = {
node_begin = node_begin,
node_add = node_add,
node_del = node_del,
node_resume = node_resume,
node_pause = node_pause,
stylesheet = stylesheet,
css_add = css_add,
css_del = css_del,
resize = resize,
bus = bus
}
return P
end)
b3b71[4] = r3b71(4, function()
local zeebo_pipeline = b3b71[32]('source_shared_functional_pipeline')
local requires = b3b71[33]('source_shared_string_dsl_requires')
local function step_install_libsys(self, lib_name, library, custom, is_system)
if not is_system then return end
local ok, msg = pcall(function()
library.install(self.std, self.engine, custom, lib_name)
end)
if ok then
self.libsys[lib_name] = true
else
self.error('sys', lib_name, msg)
end
end
local function step_check_libsys(self, lib_name, library, custom, is_system)
if not is_system then return end
if not self.libsys[lib_name] then
self.error('sys', lib_name, 'is missing!')
end
end
local function step_install_libusr(self, lib_name, library, custom, is_system)
if is_system then return end
if self.libusr[lib_name] then return end
if not requires.should_import(self.spec, lib_name) then return end
self.libusr[lib_name] = pcall(function()
library.install(self.std, self.engine, custom, lib_name)
end)
end
local function step_check_libsys_all(self)
local missing = requires.missing(self.spec, self.libusr)
if #missing > 0 then
self.error('usr', '*', 'missing libs: '..table.concat(missing, ' '))
end
end
local function package(self, lib_name, library, custom)
self.pipeline[#self.pipeline + 1] = function()
local is_system = lib_name:sub(1, 1) == '@'
local name = is_system and lib_name:sub(2) or lib_name
self:step(name, library, custom, is_system)
end
return self
end
local function setup(std, application, engine)
if not application then
error('game not found!')
end
local spec = requires.encode((application.config or application).require or '')
local self = {
std = std,
spec = spec,
errmsg = '',
engine = engine,
package = package,
libusr = {},
libsys = {},
pipeline = {},
pipe = zeebo_pipeline.pipe
}
self.error = function (prefix, lib_name, message) 
self.errmsg = self.errmsg..'['..prefix..':'..lib_name..'] '..message..'\n'
end
self.run = function()
self.step = step_install_libsys
zeebo_pipeline.reset(self)
zeebo_pipeline.run(self)
self.step = step_check_libsys
zeebo_pipeline.reset(self)
zeebo_pipeline.run(self)
self.step = step_install_libusr
zeebo_pipeline.reset(self)
zeebo_pipeline.run(self)
step_check_libsys_all(self)
if #self.errmsg > 0 then
error(self.errmsg, 0)
end
end
return self
end
local P = {
setup = setup
}
return P
end)
b3b71[5] = r3b71(5, function()
local eval_file = b3b71[34]('source_shared_string_eval_file')
local eval_code = b3b71[35]('source_shared_string_eval_code')
local has_io_open = io and io.open
local function normalize(app, base)
if not app then return nil end
if not app.callbacks then
local old_app = app
app = {meta={},config={},callbacks={}, data={}, envs={}}
for key, value in pairs(old_app) do
local is_function = type(value) == 'function'
if base.meta and base.meta[key] and not is_function then
app.meta[key] = value
elseif base.config and base.config[key] and not is_function then
app.config[key] = value
elseif is_function then
app.callbacks[key] = value
elseif app[key] then
app[key] = value
else
app.data[key] = value
end
end
end
local function defaults(a, b, key)
if type(a[key]) ~= "table" then a[key] = {} end
for k, v in pairs(b[key]) do
if a[key][k] == nil then
a[key][k] = b[key][k]
end
end
end
for field in pairs(base) do
defaults(app, base, field)
end
return app
end
local function script(src, base)
if not src and package and package.jspath then
src = {}
end
if type(src) == 'table' or type(src) == 'userdata' then
return normalize(src, base)
end
local application = type(src) == 'function' and src
if not application then
if type(src) ~= 'string' or #src == 0 then
src = 'game'
end
if src:find('\n') then
local ok, app = eval_code.script(src)
application = ok and app
else
local ok, app = eval_file.script(src)
application = ok and app
end
if not application and has_io_open then
local app_file = io.open(src)
if app_file then
local app_src = app_file:read('*a')
local ok, app = eval_code.script(app_src)
application = ok and app
app_file:close()
end
end
end     
while type(application) == 'function' do
application = application()
end
return normalize(application, base)
end
local P = {
script = script
}
return P
end)
b3b71[6] = r3b71(6, function()
local function draw_fps(std, engine, show, pos_x, pos_y)
if show < 1 then return end
local x = engine.current.config.offset_x + pos_x
local y = engine.current.config.offset_y + pos_y
local s = 4
std.draw.color(0xFFFF00FF)
if show >= 1 then
std.draw.rect(0, x, y, 40, 24)
end
if show >= 2 then
std.draw.rect(0, x + 48, y, 40, 24)
end
if show >= 3 then
std.draw.rect(0, x + 96, y, 40, 24)
end
std.draw.color(0x000000FF)
std.text.font_size(16)
if show >= 3 then
local floor = std.math.floor or math.floor or function() return 'XX' end
local fps =  floor((1/std.delta) * 1000)
std.text.print(x + s, y, fps)
s = s + 46
end
if show >= 1 then
std.text.print(x + s, y, engine.fps)
s = s + 46
end
if show >= 2 then
std.text.print(x + s, y, engine.root.config.fps_max)
s = s + 46
end
end
local function install(std, engine)
std.app = std.app or {}
std.app.fps_show = function(show)
engine.root.config.fps_show = show
end
std.bus.listen('post_draw', function()
engine.current = engine.root
draw_fps(std, engine, engine.root.config.fps_show, 8, 8)
end)
end
local P = {
install=install
}
return P
end)
b3b71[7] = r3b71(7, function()
local function decorator_poo(object, func)
if not object or not func then return func end
return function(a, b, c, d)
return func(object, a, b, c, d)
end
end
local function decorator_line(func_draw_line)
return function(mode, verts)
local index = 4
while index <= #verts do
func_draw_line(verts[index - 3], verts[index - 2], verts[index - 1], verts[index])
index = index + 2
end
end
end
local function decorator_triangle(func_draw_poly, std, func_draw_triangle)
if not func_draw_triangle then
return func_draw_poly
end
local point = function(x, y, px, py, scale, angle, ox, oy)
local xx = x + ((ox - px) * -scale * std.math.cos(angle)) - ((ox - py) * -scale * std.math.sin(angle))
local yy = y + ((oy - px) * -scale * std.math.sin(angle)) + ((oy - py) * -scale * std.math.cos(angle))
return xx, yy
end
return function(engine_mode, verts, x, y, scale, angle, ox, oy)
if #verts ~= 6 then
return func_draw_poly(engine_mode, verts, x, y, scale, angle, ox, oy)
end
ox = ox or 0
oy = oy or ox or 0
local x1, y1 = point(x, y, verts[1], verts[2], scale, angle, ox, oy)
local x2, y2 = point(x, y, verts[3], verts[4], scale, angle, ox, oy)
local x3, y3 = point(x, y, verts[5], verts[6], scale, angle, ox, oy)
return func_draw_triangle(engine_mode, x1, y1, x2, y2, x3, y3)
end
end
local function decorator_poly(func_draw_poly, std, modes, repeats)
local func_repeat = function(verts, mode)
if repeats and repeats[mode + 1] then
verts[#verts + 1] = verts[1]
verts[#verts + 1] = verts[2]
end
end
return function (engine_mode, verts, x, y, scale, angle, ox, oy)
if #verts < 6 or #verts % 2 ~= 0 then return end
local mode = modes and modes[engine_mode + 1] or engine_mode
local rotated = std.math.cos and angle and angle ~= 0
ox = ox or 0
oy = oy or ox or 0
if x and y and not rotated then
local index = 1
local verts2 = {}
scale = scale or 1
while index <= #verts do
if index % 2 ~= 0 then
verts2[index] = x + (verts[index] * scale)
else
verts2[index] = y + (verts[index] * scale)
end
index = index + 1
end
func_repeat(verts2, engine_mode)
func_draw_poly(mode, verts2)
elseif x and y then
local index = 1
local verts2 = {}
while index < #verts do
local px = verts[index]
local py = verts[index + 1]
local xx = x + ((ox - px) * -scale * std.math.cos(angle)) - ((ox - py) * -scale * std.math.sin(angle))
local yy = y + ((oy - px) * -scale * std.math.sin(angle)) + ((oy - py) * -scale * std.math.cos(angle))
verts2[index] = xx
verts2[index + 1] = yy
index = index + 2
end
func_repeat(verts2, engine_mode)
func_draw_poly(mode, verts2)
else
func_draw_poly(mode, verts)
end
end
end
local function decorator_position(engine, func)
return function(mode, verts, pos_x, pos_y, scale, angle, ox, oy)
local x = engine.current.config.offset_x + (pos_x or 0)
local y = engine.current.config.offset_y + (pos_y or 0)
ox = ox or 0
oy = ox or oy or 0
scale = scale or 1
angle = angle or 0
return func(mode, verts, x, y, scale, angle, ox, oy)
end
end
local function install(std, engine, config)
local draw_line = decorator_poo(config.object, config.line)
local draw_poly = decorator_poo(config.object, config.poly) or decorator_line(draw_line)
local draw_poly2 = config.poly2 or decorator_poly(draw_poly, std, config.modes, config.repeats)
local draw_verts = decorator_triangle(draw_poly2, std, config.triangle)
std.draw.poly = decorator_position(engine, draw_verts)
end
local P = {
install=install
}
return P
end)
b3b71[8] = r3b71(8, function()
local function text_put(std, engine, font_previous)
return function(pos_x, pos_y, text, size)
size = size or 2
local hem = engine.current.data.width / 80
local vem = engine.current.data.height / 24
local font_size = hem * size
std.text.font_default(0)
std.text.font_size(font_size)
std.text.print(pos_x * hem, pos_y * vem, text)
font_previous()
end
end
local function text_print_ex(std, engine)
return function(x, y, text, align_x, align_y)
local w, h = std.text.mensure(text)
local aligns_x, aligns_y = {w, w/2, 0}, {h, h/2, 0}
std.text.print(x - aligns_x[(align_x or 1) + 2], y - aligns_y[(align_y or 1) + 2], text)
return w, h
end
end
local function install(std, engine, config)
std.text.font_previous = config.font_previous
std.text.is_tui = config.is_tui or function() return false end
std.text.print_ex = text_print_ex(std, engine)
std.text.put = text_put(std, engine, config.font_previous)
end
local P = {
install=install
}
return P
end)
b3b71[9] = r3b71(9, function()
local ui_jsx = b3b71[36]('source_engine_api_draw_ui_jsx')
local ui_grid = b3b71[37]('source_engine_api_draw_ui_grid')
local ui_slide = b3b71[38]('source_engine_api_draw_ui_slide')
local ui_style = b3b71[39]('source_engine_api_draw_ui_style')
local util_decorator = b3b71[2]('source_shared_functional_decorator')
local function install(std, engine, application)
std.ui = std.ui or {}
std.h = function(a, b, ...) return ui_jsx.h(std, engine, a, b, {...}) end
std.ui.grid = util_decorator.prefix2(std, engine, ui_grid.component)
std.ui.slide = util_decorator.prefix2(std, engine, ui_slide.component)
std.ui.style = util_decorator.prefix1(engine, ui_style.component)
end
local P = {
install=install
}
return P
end)
b3b71[10] = r3b71(10, function()
local function image_draw(func, engine)
return function(src, pos_x, pos_y)
local x = engine.offset_x + (pos_x or 0)
local y = engine.offset_y + (pos_y or 0)
func(src, x, y)
end  
end
local function image_mensure(func)
return function(src)
return func(src)
end
end
local function image_load(func)
return function(src, url_wip)
return func(src, url_wip)
end
end
local function image_exists(func)
return function(src)
return not not func(src)
end
end
local function image_unload(func)
return function(src)
return func(src)
end
end
local function image_unload_all(func)
return function(src)
return func(src)
end
end
local function install(std, engine, func)
local f = func.unload or function() end
std.image.load = image_load(func.load)
std.image.draw = image_draw(func.draw, engine)
std.image.exists = image_exists(func.load)
std.image.mensure = image_mensure(func.mensure)
std.image.unload = image_unload(func.unload or f)
std.image.unload_all = image_unload_all(func.unload_all or f)
std.image.mensure_width = function(v) return select(1, std.image.mensure(v)) end
std.image.mensure_height = function(v) return select(2, std.image.mensure(v)) end
end
return {
install = install
}
end)
b3b71[11] = r3b71(11, function()
local util_decorator = b3b71[2]('source_shared_functional_decorator')
local function array_map(array, func)
local res = {}
local index = 1
local length = #array
while index <= length do
res[#res + 1] = func(array[index], index)
index = index + 1
end
return res
end
local function array_filter(array, func)
func = func or (function(v) return v and v ~= 0 end)
local res = {}
local index = 1
local length = #array
while index <= length do
local value = array[index]
if func(value, index) then
res[#res + 1] = value
end
index = index + 1
end
return res
end
local function array_unique(array)
local res = {}
local index = 1
local length = #array
local setmap = {}
while index <= length do
local value = array[index]
if not setmap[value] then
res[#res + 1] = value
end
setmap[value] = true
index = index + 1
end
return res
end
local function array_foreach(array, func)
local index = 1
local length = #array
while index <= length do
func(array[index], index)
index = index + 1
end
end
local function array_reducer(array, func, value)
local index = value and 1 or 2
local length = #array
value = value or array[1]
while index <= length do
value = func(value, array[index], index)
index = index + 1
end
return value
end
local function array_index(array, func, reverse)
func = func or function() return true end
local index, inc, final = 1, 1, #array
if reverse then
index, inc, final = #array, -1, 1
end
repeat
if func(array[index], index) then
return index
end
index = index + inc
until (reverse and index < final) or (not reverse and index > final)
return nil
end
local function array_first(array, func)
local index = array_index(array, func)
if index then
return array[index]
end
return nil
end
local function array_last(array, func)
local index = array_index(array, func, true)
if index then
return array[index]
end
return nil
end
local function array_some(array, func, reverse)
local index, inc, final = 1, 1, #array
if reverse then
index, inc, final = #array, -1, 1
end
repeat
if func(array[index], index) then
return true
end
index = index + inc
until (reverse and index < final) or (not reverse and index > final)
return false
end
local function array_every(array, func)
local index = 1
local length = #array
while index <= length do
if not func(array[index], index) then
return false
end
index = index + 1
end
return true
end
local function array_pipeline(std, array)
local decorator_iterator = function(func) 
return function(self, func2, extra)
self.array = func(self.array, func2, extra)
return self
end
end
local decorator_reduce = function(func, return_self)
return function(self, func2, extra)
local res = func(self.array, func2, extra)
return (return_self and self) or res
end
end
local self = {
array = array,
map = decorator_iterator(array_map),
filter = decorator_iterator(array_filter),
unique = decorator_iterator(array_unique),
each = decorator_reduce(array_foreach, true),
reducer = decorator_reduce(array_reducer),
index = decorator_reduce(array_index),
first = decorator_reduce(array_first),
last = decorator_reduce(array_last),
some = decorator_reduce(array_some),
every = decorator_reduce(array_every),
table = function(self) return self.array end,
json = function(self) return std.json.encode(self.array) end
}
return self
end
local function install(std, engine, library, name)
local lib = std[name] or {}
lib.map = array_map
lib.filter = array_filter
lib.unique = array_unique
lib.each = array_foreach
lib.reducer = array_reducer
lib.index = array_index
lib.first = array_first
lib.last = array_last
lib.some = array_some
lib.every = array_every
lib.from = util_decorator.prefix1(std, array_pipeline)
std[name] = lib
end
local P = {
install = install
}
return P
end)
b3b71[12] = r3b71(12, function()
local function install(std, engine, library, name)
std = std or {}
std[name] = {
encode=library.encode,
decode=library.decode
}
return {[name]=std[name]}
end
local P = {
install=install
}
return P
end)
b3b71[13] = r3b71(13, function()
local function djb2(digest)
local index = 1
local hash = 5381
while index <= #digest do
local char = string.byte(digest, index)
hash = (hash * 33 + char) % 4294967296
index = index + 1
end
return hash
end
local function install(std, engine, cfg_system)
local id = djb2(cfg_system.get_secret())
std = std or {}
std.hash = std.hash or {}
std.hash.djb2 = djb2
std.hash.fingerprint = function() return id end
end
local P = {
install = install
}
return P
end)
b3b71[14] = r3b71(14, function()
local language = 'en-US'
local language_default = 'en-US'
local language_list = {}
local language_inverse_list = {}
local translate = {}
local function update_languages(texts)
local index = 1
translate = texts
language_list = {language_default}
language_inverse_list = {[language_default]=1}
repeat
local lang = next(texts)
if lang then
index = index + 1
language_inverse_list[lang] = index
language_list[#language_list + 1] = lang
end
until lang
end
local function get_text(old_text)
local new_text = translate[language] and translate[language][old_text]
return new_text or old_text
end
local function get_language()
return language
end
local function set_language(l)
if language_inverse_list[l] then
language = l
else 
language = language_default
end
end
local function next_language(to)
local index = language_inverse_list[language]
local incr = to or 1
if index then
index = index + incr
if index > #language_list then
index = 1
end
if index <= 0 then
index = #language_list
end
index = index == 0 and 1 or index
set_language(language_list[index])
end
end
local function back_language()
next_language(-1)
end
local function decorator_draw_text(func)
return function (x, y, text, a, b, c)
return func(x, y, get_text(text), a, b, c)
end
end
local function install(std, engine, cfg)
if not (std and std.text and std.text.print) then
error('missing draw text')
end
local old_put = std.text.put
local old_print = std.text.print
local old_print_ex = std.text.print_ex
local callback_lang = function(result)
update_languages(result)
if cfg and cfg.get_language then
set_language(cfg.get_language())
end
end
if not std.node and engine.root.callbacks.i18n then
callback_lang(engine.root.callbacks.i18n())
else
std.bus.listen('ret_i18n', callback_lang)
std.bus.emit_next('i18n')
end
std.text.put = decorator_draw_text(old_put)
std.text.print = decorator_draw_text(old_print)
std.text.print_ex = decorator_draw_text(old_print_ex)
std.i18n = {}
std.i18n.get_text = get_text
std.i18n.get_language = get_language
std.i18n.set_language = set_language
std.i18n.back = back_language
std.i18n.next = next_language
end
local P = {
install=install
}
return P
end)
b3b71[15] = r3b71(15, function()
local yaml = b3b71[40]('source_shared_string_encode_yaml')
local levels = { none = 0, fatal = 1, error = 2, warn = 3, info = 4, debug = 5, trace = 6}
local function printer(engine, printers, func_a, func_b)
local fn_a = func_a and printers[func_a]
local fn_b = func_b and printers[func_b]
local func = fn_a or fn_b or function() end
local level = levels[func_a] or 7
return function (...)
local msgs = {...}
local count = #msgs
if level <= engine.loglevel then
local content = ''
for i = 1, count do
local v = msgs[i]
local t = type(v)
if t == 'table' then
content = content..'\n'..yaml.encode(v)..'\n'
elseif t ~= 'function' then
local add_space = i ~= count and i > 1 and content:sub(-1) ~= '\n'
local prefix = add_space and ' ' or ''
content = content..prefix..tostring(v)
end
end
func(content)
end
end
end
local function level(engine)
return function(n)
local lv = levels[n] or (type(n) == 'number' and n) or -1
if lv < 0 or 6 < lv then
error('logging level not exist: '..tostring(level)) 
end
engine.loglevel = lv
end
end
local function init(std, engine)
return function(printers)
std.log.fatal = printer(engine, printers, 'fatal', 'error')
std.log.error = printer(engine, printers, 'error')
std.log.warn = printer(engine, printers, 'warn')
std.log.info = printer(engine, printers, 'info')
std.log.debug = printer(engine, printers, 'debug', 'info')
std.log.trace = printer(engine, printers, 'trace', 'info')
end    
end
local function install(std, engine, printers)
std.log = std.log or {}
std.log.init = init(std, engine)
std.log.level = level(engine)
std.log.init(printers)
std.log.level('debug')
end
local P = {
install = install
}
return P
end)
b3b71[16] = r3b71(16, function()
local zeebo_pipeline = b3b71[32]('source_shared_functional_pipeline')
local function json(self)
self.options['json'] = true
return self
end
local function noforce(self)
self.options['noforce'] = true
return self
end
local function fast(self)
self.speed = '_fast'
return self
end
local function param(self, name, value)
local index = #self.param_list + 1
self.param_list[index] = tostring(name)
self.param_dict[name] = tostring(value)
return self
end
local function header(self, name, value)
local index = #self.header_list + 1
self.header_list[index] = tostring(name)
self.header_dict[name] = tostring(value)
return self
end
local function body(self, content, json_encode)
if type(content) == 'table' then
header(self, 'Content-Type', 'application/json')
content = json_encode(content)
end
self.body_content=content
return self
end
local function success(self, handler_func)
self.success_handler = handler_func
return self
end
local function failed(self, handler_func)
self.failed_handler = handler_func
return self
end
local function http_error(self, handler_func)
self.error_handler = handler_func
return self
end
local function request(method, std, engine, protocol)
local callback_handler = function()
if std.node then
std.node.emit(engine.current, 'http')
elseif engine.current.callbacks.http then
engine.current.callbacks.http(std, engine.current.data)
end
end
return function (url)
local json_encode = std.json and std.json.encode
local json_decode = std.json and std.json.decode
local http_body = function(self, content) return body(self, content, json_encode) end
local game = engine.current.data
local self = {
url = url,
speed = '',
options = {},
method = method,
body_content = '',
header_list = {},
header_dict = {},
param_list = {},
param_dict = {},
success_handler = function (std, game) end,
failed_handler = function (std, game) end,
error_handler = function (std, game) end,
fast = fast,
json = json,
noforce = noforce,
body = http_body,
param = param,
header = header,
success = success,
failed = failed,
error = http_error,
run = zeebo_pipeline.run,
}
self.promise = function()
zeebo_pipeline.stop(self)
end
self.resolve = function()
zeebo_pipeline.resume(self)
end
self.set = function (key, value)
std.http[key] = value
end
self.pipeline = {
function()
self.id = tonumber(tostring({}):gsub('0x', ''):match('^table: (%w+)$'), 16)
engine.http[self.id] = self
if protocol.force and not self.options['noforce'] then
self.url = url:gsub("^[^:]+://", protocol.force.."://")
end
end,
function()
protocol.handler(self, self.id)
end,
function()
if self.options['json'] and json_decode and std.http.body then
local ok, err = pcall(function()
local new_body = json_decode(std.http.body)
std.http.body = new_body
end)
if not ok then
self.set('ok', false)
self.set('error', err)
end
end
local lower_header = {}
for k, v in pairs(std.http.headers or {}) do
lower_header[string.lower(k)] = v
end
std.http.headers = lower_header
end,
function()
callback_handler(std, game)
if std.http.ok then
self.success_handler(std, game)
elseif std.http.error then
self.error_handler(std, game)
elseif not std.http.status then
self.set('error', 'missing protocol response')
self.error_handler(std, game)
else
self.failed_handler(std, game)
end
end,
function ()
std.http.ok = nil
std.http.body = nil
std.http.error = nil
std.http.status = nil
std.http.body_is_table = nil
end,
function()
engine.http[self.id] = nil
zeebo_pipeline.reset(self)
end
}
return self
end
end
local function install(std, engine, protocol)
assert(protocol and protocol.handler, 'missing protocol handler')
engine.http = {}
std.http = std.http or {}
std.http.get=request('GET', std, engine, protocol)
std.http.head=request('HEAD', std, engine, protocol)
std.http.post=request('POST', std, engine, protocol)
std.http.put=request('PUT', std, engine, protocol)
std.http.delete=request('DELETE', std, engine, protocol)
std.http.patch=request('PATCH', std, engine, protocol)
if protocol.install then
protocol.install(std, engine)
end
end
local P = {
install=install
}
return P
end)
b3b71[17] = r3b71(17, function()
local function media_create(node, channels, handler)
local decorator = function(func)
func = func or function() end
return function(self, a, b, c, d, e, f)
func(0, a, b, c, d, e, f)
return self
end
end
local self = { 
src = decorator(handler.source),
play = decorator(handler.play),
prepare = decorator(handler.prepare),
pause = decorator(handler.pause),
resume = decorator(handler.resume),
stop = decorator(handler.stop),
position = decorator(handler.position),
in_mutex = handler.mutex or function() return false end,
get_error = handler.error or function() return nil end,
node = node,
apply = function() end
}
return function()
return self
end
end
local function install(std, engine, handler, name)
std.media = std.media or {}
local mediatype = name:match('%w+%.(%w+)')
if handler.install then
handler.install(std, engine, mediatype, name)
end
if not std.media[mediatype] then
local channels = handler.bootstrap and handler.bootstrap(mediatype)
if (not channels or channels == 0) and handler.bootstrap then
error('media '..mediatype..' is not supported!')
end
local node = std.node and std.node.load({})
std.media[mediatype] = media_create(node, channels, handler)
end
end
local P = {
install=install
}
return P
end)
b3b71[18] = r3b71(18, function()
local zeebo_pipeline = b3b71[32]('source_shared_functional_pipeline')
local function storage_as(engine, self, name, cast)
if cast == nil then
cast = function(v) return v end
elseif type(cast) ~= 'function' then
local value = cast
cast = function() return value end
end
local node = engine.current
self.callbacks[#self.callbacks + 1] = function(value)
node.data[name] = cast(value)
end
return self
end
local function storage_callback(self, handler)
self.callbacks[#self.callbacks + 1] = handler
return self
end
local function storage_default(self, value)
self.default_value = tostring(value)
return self
end
local function storage_command(cmd, std, engine, handlers)
return function(name, value)
if type(value) == 'table' and std.json then
value = std.json.encode(value)
end
value = tostring(value or '')
local self = {
value = '',
default_value = '',
default = storage_default,
callback = storage_callback,
as = function(a, b, c) return storage_as(engine, a, b, c) end,
run = zeebo_pipeline.run,
callbacks = {}
}
self.promise = function() zeebo_pipeline.stop(self) end
self.resolve = function() zeebo_pipeline.resume(self) end
self.pipeline = {
function()
if cmd == 'set' then
handlers.set(name, value or '',  self.promise, self.resolve)
elseif cmd == 'get' then
local save = function(value) self.value = value end
handlers.get(name, save, self.promise, self.resolve)
end
end,
function()
if type(self.value) ~= 'string' or #self.value == 0 then
self.value = #self.default_value > 0 and self.default_value or nil
end
end,
function()
local index = 1
while index <= #self.callbacks do
self.callbacks[index](self.value)
index = index + 1
end
end
}
return self
end
end
local function storage_mutex(mutex_func)
return function()
if mutex_func then return mutex_func() end
return false
end
end
local function install(std, engine, handlers)
if handlers.install then
handlers.install(std, engine)
end
if not handlers.set or not handlers.get then
error('missing handlers')
end
std.storage = std.storage or {}
std.storage.in_mutex = storage_mutex(handlers.mutex)
std.storage.set = storage_command('set', std, engine, handlers)
std.storage.get = storage_command('get', std, engine, handlers)
end
local P = {
install=install
}
return P
end)
b3b71[19] = r3b71(19, function()
local ev_prefixes = {
'pre_',
'',
'post_'
}
local buses = {
list = {},
dict = {},
queue = {},
all = {}
}
local must_abort = false
local function abort()
must_abort = true
end
local function emit_next(key, a, b, c, d, e, f)
buses.queue[#buses.queue + 1] = {key, a, b, c, d, e, f}
end
local function emit(engine, prefixes, key, a, b, c, d, e, f)
local index1, index2, index3 = 1, 1, 1
while index1 <= #prefixes do
index2 = 1
local prefix = prefixes[index1]
local topic = prefix..key
local bus = buses.dict[topic]
while not must_abort and bus and index2 <= #bus do
xpcall(function() bus[index2](a, b, c, d, e, f) end, engine.handler)
index2 = index2 + 1
end
index3 = 1
while index3 <= #buses.all do
xpcall(function() buses.all[index3](topic, a, b, c, d, e, f) end, engine.handler)
index3 = index3 + 1
end
index1 = index1 + 1
end
must_abort = false
end
local function trigger(engine)
return function (key)
return function (a, b, c, d, e, f)
emit(engine, ev_prefixes, key, a, b, c, d, e, f)
end
end
end
local function listen(key, handler_func)
if not key or not handler_func then return end
if not buses.dict[key] then
buses.list[#buses.list + 1] = key
buses.dict[key] = {}
end
local index = #buses.dict[key] + 1
buses.dict[key][index] = handler_func 
end
local function listen_all(handler_func)
buses.all[#buses.all + 1] = handler_func
end
local function install(std, engine)
std.bus = std.bus or {}
std.bus.abort = abort
std.bus.listen = listen
std.bus.trigger = trigger(engine)
std.bus.emit_next = emit_next
std.bus.listen_all = listen_all
engine.bus_emit_ret = function(key, a)
emit(engine, {'ret_'}, key, a)
end
std.bus.emit = function(key, a, b, c, d, e, f)
emit(engine, ev_prefixes, key, a, b, c, d, e, f)
end
std.bus.listen_std = function(key, handler_func)
listen(key, function(a, b, c, d, e, f)
handler_func(std, a, b, c, d, e, f)
end)
end
std.bus.listen_std_data = function(key, handler_func)
listen(key, function(a, b, c, d, e, f)
handler_func(std, engine.current.data, a, b, c, d, e, f)
end)
end
std.bus.listen_std_engine = function(key, handler_func)
listen(key, function(a, b, c, d, e, f)
handler_func(std, engine, a, b, c, d, e, f)
end)
end
listen('pre_loop', function()
local index = 1
while index <= #buses.queue do
local pid = buses.queue[index]
emit(engine, {''}, pid[1], pid[2], pid[3], pid[4], pid[5], pid[6])
index = index + 1
end
buses.queue = {}
end)
return {
bus=std.bus
}
end
local P = {
install=install
}
return P
end)
b3b71[20] = r3b71(20, function()
local memory_dict_unload = {}
local memory_dict = {}
local memory_list = {}
local function cache_get(key)
return memory_dict[key]
end
local function cache_set(key, load_func, unload_func)
local value = load_func()
memory_list[#memory_list + 1] = key
memory_dict_unload[key] = unload_func
memory_dict[key] = value
end
local function cache(key, load_func, unload_func)
local value = cache_get(key)
if value == nil then
cache_set(key, load_func, unload_func)
value = cache_get(key)
end    
return value
end
local function unset(key)
if memory_dict_unload[key] then
memory_dict_unload[key](memory_dict[key])
end
memory_dict[key] = nil
end
local function gc_clear_all()
local index = 1
local items = #memory_list
while index <= items do
unset(memory_list[index])
index = index + 1
end
memory_list = {}
return items
end
local function install(std)
std = std or {}
std.mem = std.mem or {}
std.mem.cache = cache
std.mem.cache_get = cache_get
std.mem.cache_set = cache_set
std.mem.unset = unset
std.mem.gc_clear_all = gc_clear_all
return {
mem=std.mem
}
end
local P = {
install=install
}
return P
end)
b3b71[21] = r3b71(21, function()
local tree = b3b71[3]('source_shared_engine_tree')
local loadgame = b3b71[5]('source_shared_engine_loadgame')
local node_default = b3b71[41]('source_shared_var_object_node')
local function emit(std, application, key, a, b, c, d, e, f)
end
local function load(application)
return loadgame.script(application, node_default)
end
local function spawn(engine)
return function(application, parent)
tree.node_add(engine.dom, application, {parent=parent or engine.current})
return application
end
end
local function kill(engine)
return function(application)
tree.node_del(engine.dom, application)
end
end
local function pause(engine)
return function(application, key)
tree.node_pause(engine.dom, application, key)
end
end
local function resume(engine)
return function(application, key)
tree.node_resume(engine.dom, application, key)
end
end
local function install(std, engine)
std.node = std.node or {}
std.node.kill = kill(engine)
std.node.pause = pause(engine)
std.node.spawn = spawn(engine)
std.node.resume = resume(engine)
std.node.load = load
std.node.emit = function(application, key, a, b, c, d, e, f)
return emit(std, application, key, a, b, c, e, f)
end
std.bus.listen_all(function(key, a, b, c, d, e, f)
tree.bus(engine.dom, key, function(node)
engine.current = node
engine.offset_x = node.config.offset_x
engine.offset_y = node.config.offset_y
if node.callbacks[key] then
xpcall(function() node.callbacks[key](node.data, std, a, b, c, d, e, f) end, engine.handler)
end
end)
end)
end
local P = {
install=install
}
return P
end)
b3b71[22] = r3b71(22, function()
local function setenv(engine)
return function(varname, value)
if engine.root ~= engine.current then
error('unauthorized set environment', 0)
end
if varname then
engine.overrides_envs[varname] = tostring(value)
end
end
end
local function getenv(engine, get_env)
return function(varname) 
local game_envs = engine.root and engine.root.envs
local core_envs = engine.envs
if not (varname or #varname > 0) then
return nil
end
if engine.overrides_envs[varname] then
return engine.overrides_envs[varname]
end
if game_envs and game_envs[varname] then
return game_envs[varname]
end
if core_envs and core_envs[varname] then
return core_envs[varname]
end    
if get_env then
return get_env(varname)
end
return nil
end
end
local function install(std, engine, cfg)
engine.overrides_envs = {}
std.getenv = getenv(engine, cfg.get_env)
std.setenv = setenv(engine)
end
local P = {
install = install
}
return P
end)
b3b71[23] = r3b71(23, function()
local function install(std)
std.color = std.color or {}
std.color.white = 0xFFFFFFFF
std.color.lightgray = 0xC8CCCCFF
std.color.gray = 0x828282FF
std.color.darkgray = 0x505050FF
std.color.yellow = 0xFDF900FF
std.color.gold = 0xFFCB00FF
std.color.orange = 0xFFA100FF
std.color.pink = 0xFF6DC2FF
std.color.red = 0xE62937FF
std.color.maroon = 0xBE2137FF
std.color.green = 0x00E430FF
std.color.lime = 0x009E2FFF
std.color.darkgreen = 0x00752CFF
std.color.skyblue = 0x66BFFFFF
std.color.blue = 0x0079F1FF
std.color.darkblue = 0x0052ACFF
std.color.purple = 0xC87AFFFF
std.color.violet = 0x873CBEFF
std.color.darkpurple = 0x701F7EFF
std.color.beige = 0xD3B083FF
std.color.brown = 0x7F6A4FFF
std.color.darkbrown = 0x4C3F2FFF
std.color.black = 0x000000FF
std.color.blank = 0x00000000
std.color.magenta = 0xFF00FFFF
end
local P = {
install = install
}
return P
end)
b3b71[24] = r3b71(24, function()
local function reset(std, engine)
if std.node then
return function()
std.bus.emit('exit')
std.bus.emit('init')
end
end
return function()
engine.root.callbacks.exit(engine.root.data, std)
engine.root.callbacks.init(engine.root.data, std)
end
end
local function exit(std)
return function()
std.bus.emit('exit')
std.bus.emit('quit')
end
end
local function title(func)
return function(window_name)
if func then
func(window_name)
end
end
end
local function get_info(my, info)
return function()
return my.root.meta[info]
end
end
local function install(std, engine, config)
std = std or {}
config = config or {}
std.app = std.app or {}
std.bus.listen('post_quit', config.quit or config.exit or function() end)
std.app.title = title(config.set_title)
std.app.exit = exit(std)
std.app.reset = reset(std, engine)
std.app.get_name = get_info(engine, 'title')
std.app.get_version = get_info(engine, 'version')
std.app.get_fps = config.get_fps
return std.app
end
local P = {
install=install
}
return P
end)
b3b71[25] = r3b71(25, function()
local function real_key(std, engine, rkey, rvalue)
local value = (rvalue == 1 or rvalue == true) or false
local key = engine.key_bindings[rkey] or (std.key.axis[rkey] and rkey)
local key_media = std.key.media and std.key.media[rkey] ~= nil and rkey
if key_media then
std.key.media[key_media] = value
std.bus.emit('key_media')
end
if key then
std.key.axis[key] = value and 1 or 0
std.key.press[key] = value
if key == 'right' or key == 'left' then
std.key.axis.x = std.key.axis.right - std.key.axis.left
end
if key == 'down' or key == 'up' then
std.key.axis.y = std.key.axis.down - std.key.axis.up
end
std.bus.emit('key')
end
local a = std.key.axis
std.key.press.any = (a.left + a.right + a.down + a.up + a.a + a.b + a.c + a.d + a.menu) > 0
end
local function real_keydown(std, engine, key)
real_key(std, engine, key, 1)
end
local function real_keyup(std, engine, key)
real_key(std, engine, key, 0)
end
local function install(std, engine, config)
config = config or {}
engine.key_bindings = config.bindings or {}
engine.keyboard = real_key
if config.has_media then
std.key.media = {
ch_up = false,
ch_down = false,
vol_up = false,
vol_down = false
}
end
std.bus.listen_std_engine('rkey', real_key)
std.bus.listen_std_engine('rkey1', real_keydown)
std.bus.listen_std_engine('rkey0', real_keyup)
end
return {
install = install
}
end)
b3b71[26] = r3b71(26, function()
local function abs(value)
if value < 0 then
return -value
end
return value
end
local function clamp(value, value_min, value_max)
if value < value_min then
return value_min
elseif value > value_max then
return value_max
else
return value
end
end
local function clamp2(value, value_min, value_max)
return (value - value_min) % (value_max - value_min + 1) + value_min
end
local function dir(value, alpha)
alpha = alpha or 0
if value < -alpha then
return -1
elseif value > alpha then
return 1
else
return 0
end
end
local function dis(x1,y1,x2,y2)
local sqr = 1/2
return ((x2 - x1) ^ 2 + (y2 - y1) ^ 2) ^ (sqr ~= 0 and sqr or 1)
end
local function dis2(x1,y1,x2,y2)
return (x2 - x1) ^ 2 + (y2 - y1) ^ 2
end
local function dis3(x1,y1,x2,y2)
return abs(x1 - x2) + abs(x2 - y2)
end
local function lerp(a, b, alpha)
return a + alpha * ( b - a )
end 
local function map(value, in_min, in_max, out_min, out_max)
return (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
end
local function max(...)
local args = {...}
local index = 1
local value = nil
local max_value = nil
if #args == 1 then
args = args[1]
end
while index <= #args do
value = args[index]
if max_value == nil or value > max_value then
max_value = value
end
index = index + 1
end
return max_value
end
local function min(...)
local args = {...}
local index = 1
local value = nil
local min_value = nil
if #args == 1 then
args = args[1]
end
while index <= #args do
value = args[index]
if min_value == nil or value < min_value then
min_value = value
end
index = index + 1
end
return min_value
end
local function install(std)
std.math = std.math or {}
std.math.abs=abs
std.math.clamp=clamp
std.math.clamp2=clamp2
std.math.dir=dir
std.math.dis=dis
std.math.dis2=dis2
std.math.dis3=dis3
std.math.lerp=lerp
std.math.map=map
std.math.max=max
std.math.min=min
end
local P = {
install = install
}
return P
end)
b3b71[27] = r3b71(27, function()
local function install(std)
assert(math and (1/2 ~= 0))
std.math = std.math or {}
std.math.acos=math.acos
std.math.asin=math.asin
std.math.atan=math.atan
std.math.atan2=math.atan2
std.math.ceil=math.ceil
std.math.cos=math.cos
std.math.cosh=math.cosh
std.math.deg=math.deg
std.math.exp=math.exp
std.math.floor=math.floor
std.math.fmod=math.fmod
std.math.frexp=math.frexp
std.math.huge=math.huge
std.math.ldexp=math.ldexp
std.math.log=math.log
std.math.log10=math.log10
std.math.modf=math.modf
std.math.pi=math.pi
std.math.pow=math.pow
std.math.rad=math.rad
std.math.sin=math.sin
std.math.sinh=math.sinh
std.math.sqrt=math.sqrt
std.math.tan=math.tan
std.math.tanh=math.tanh
end
local P = {
install = install
}
return P
end)
b3b71[28] = r3b71(28, function()
local function install(std)
assert(math and (1/2 ~= 0))
std.math = std.math or {}
std.math.random = function(a, b)
a = a and math.floor(a)
b = b and math.floor(b)
if a > b then a, b = b, a end
return math.random(a, b)
end
end
local P = {
install = install
}
return P
end)
b3b71[29] = r3b71(29, function()
local str_http = b3b71[43]('source_shared_string_encode_http')
local str_url = b3b71[44]('source_shared_string_encode_url')
local callbacks = {
['async-promise'] = function(self)
return self:promise()
end,
['async-resolve'] = function(self)
return self:resolve()
end,
['get-url'] = function(self)
return self.url
end,
['get-fullurl'] = function(self)
return self.url..str_url.search_param(self.param_list, self.param_dict)
end,
['get-method'] = function(self)
return self.method
end,
['get-body'] = function(self)
return self.body_content
end,
['get-param-count'] = function(self)
return #self.param_list
end,
['get-param-name'] = function(self, data)
return self.param_list[self.data]
end,
['get-param-data'] = function(self, data)
return self.param_dict[self.data] or self.param_dict[self.param_list[self.data]]
end,
['get-header-count'] = function(self)
return #self.header_list
end,
['get-header-name'] = function(self, data)
return self.header_list[self.data]
end,
['get-header-data'] = function(self, data)
return self.heeader_dict[self.data] or self.heeader_dict[self.header_list[self.data]]
end,
['set-status'] = function(self, data)
self.set('status', data)
self.set('ok', str_http.is_ok(data))
end,
['set-error'] = function(self, data)
self.set('error', data)
end,
['set-ok'] = function(self, data)
self.set('ok', data)
end,
['set-body'] = function(self, data)
self.set('body', data)
end,
['set-headers'] = function(self, data)
self.set('headers', data or {})
end,
['add-body-data'] = function(self, data, std)
self.set('body', (std.http.body or '')..data)
end    
}
local function native_http_callback(self, evt, data, std)
if not callbacks[evt] then
error('http evt '..evt..' not exist!')
end
return callbacks[evt](self, data, std)
end
local P = {
func = native_http_callback
}
return P
end)
b3b71[30] = r3b71(30, function()
local P = {
data={
width=1280,
height=720
},
meta={
id='',
title='',
author='',
company='',
description='',
tizen_package='',
version=''
},
config = {
offset_x = 0,
offset_y = 0,
require = '',
fps_max = 60,
fps_show = 0,
fps_drop = 5,
fps_time = 5
},
callbacks={
}
}
return P;
end)
b3b71[31] = r3b71(31, function()
local P = {
milis = 0,
delta = 0,
math = {
},
media = {
},
draw = {
image = function() end,
clear = function () end,
color = function () end,
rect = function () end,
line = function () end,
poly = function () end,
tui_text = function() end
},
text = {
put = function() end,
print = function() end,
mensure = function() end,
font_size = function() end,
font_name = function() end,
font_default = function() end
},
image = {
load = function() end,
draw = function() end
},
app = {
width = 1280,
height = 720,
title = function() end,
reset = function () end,
load = function() end,
exit = function () end
},
key = {
axis = {
x = 0,
y = 0,
menu=0,
up=0,
down=0,
left=0,
right=0,
a = 0,
b = 0, 
c = 0,
d = 0
},
press = {
menu=false,
up=false,
down=false,
left=false,
right=false,
a=false,
b=false,
c=false,
d=false,
any=false
}
}
}
return P;
end)
b3b71[32] = r3b71(32, function()
local function pipe(self)
return function()
self:run()
end
end
local function stop(self)
if self.pipeline and not self.pipeline2 then
self.pipeline2 = self.pipeline
self.pipeline = nil
end
end
local function resume(self)
if not self.pipeline and self.pipeline2 then
self.pipeline = self.pipeline2
self.pipeline2 = nil
self:run()
end
end
local function run(self)
self.pipeline_current = self.pipeline_current or 1
while self.pipeline and self.pipeline_current and self.pipeline_current <= #self.pipeline do
self.pipeline[self.pipeline_current]()
if self.pipeline_current then
self.pipeline_current = self.pipeline_current + 1
end
end
return self
end
local function reset(self)
self.pipeline = self.pipeline or self.pipeline2
self.pipeline2 = nil
self.pipeline_current = nil
end
local function clear(self)
self.pipeline_current = nil
self.pipeline2 = nil
self.pipeline = nil
end
local P = {
reset=reset,
clear=clear,
pipe=pipe,
stop=stop,
resume=resume,
run=run
}
return P
end)
b3b71[33] = r3b71(33, function()
local function encode(dsl_string)
local spec = {
list = {},
required = {},
all = false
}
for entry in (dsl_string or ''):gmatch("[^%s]+") do
if entry == "*" then
spec.all = true
else
local is_optional = entry:sub(-1) == "?"
local name = is_optional and entry:sub(1, -2) or entry
spec.list[#spec.list + 1] = name
spec.required[#spec.required + 1] = not is_optional
end
end
return spec
end
local function missing(spec, imported)
local result = {}
do
local index = 1
while spec.list[index] do
local name = spec.list[index]
if spec.required[index] and not imported[name] then
result[#result + 1] = name
end
index = index + 1
end
end
return result
end
local function should_import(spec, libname)
local index = 1
while spec.list[index] do
if spec.list[index] == libname then return true end
index = index + 1
end
return spec.all
end
local P = {
encode = encode,
missing = missing,
should_import = should_import
}
return P
end)
b3b71[34] = r3b71(34, function()
local function script(src)
local ok, app = false, nil
if require then
ok, app = pcall(require, src:gsub('%.lua$', ''))
end
if not ok and dofile then
ok, app =  pcall(dofile, src)
end
if not ok and loadfile then
ok, app = pcall(loadfile, src)
end
if type(app) == 'function' then
ok, app = pcall(app)
end
if not ok then
return false, 'failed to eval file'
end
return ok, app
end
local P = {
script = script,
}
return P
end)
b3b71[35] = r3b71(35, function()
local function script(src)
local loader = loadstring or load
if not loader then
error('eval not allowed')
end
local ok, chunk = pcall(loader, src)
if not ok then
return false, chunk
end
if type(chunk) ~= 'function' then
return false, 'failed to eval code'
end
return pcall(chunk)
end
local P = {
script = script,
}
return P
end)
b3b71[36] = r3b71(36, function()
local function add_style(std, node, stylesheet)
for style in stylesheet:gmatch("%S+") do
std.ui.style(style):add(node)
end 
end
local function h(std, engine, element, attribute, childs)
local el_type = type(element)
attribute = attribute or {}
if element == std then
return error
elseif element == std.h then
for i = 1, #childs do std.node.spawn(std.node.load(childs[i])) end
return childs
elseif element == std.ui then
return childs
elseif element == 'node' then
local parent = std.node.spawn(std.node.load(attribute))
for i = 1, #childs do
local c = childs[i]
if c.node then
local is_invalid = (c.span or 1) > 1 or c.offset or c.after
if is_invalid then error('[error] JSX forbidden attributes in \'node\' child') end
std.node.spawn(c.node, parent)
if c.style then add_style(std, c.node, c.style) end
else
std.node.spawn(c, parent)
end
end
return parent
elseif element == 'grid' then
local index = 1
local grid = std.ui.grid(attribute.class):dir(attribute.dir)
if attribute.style then add_style(std, grid.node, attribute.style) end
while index <= #childs do
local item = childs[index]
if item.node then
grid:add(item.node, {span=item.span, offset=item.offset, after=item.after})
if item.style then add_style(std, grid:get_item(index), item.style) end
else
grid:add(item)
end
index = index + 1
end
grid.span = attribute.span
grid.after = attribute.after
grid.style = attribute.style
grid.offset = attribute.offset
return grid
elseif element == 'item' then
return {
type='item',
node=childs[1],
span=attribute.span,
after=attribute.after,
style=attribute.style,
offset=attribute.offset
}
elseif element == 'style' then
return std.ui.style(attribute.class, attribute)
elseif el_type == 'function' then
attribute.children = (childs and #childs > 1) and childs or childs[1]
return element(attribute, std)
elseif el_type == 'table' then
return element
else
error('[error] JSX invalid element type: '..el_type)
end
end
local P = {
h = h
}
return P
end)
b3b71[37] = r3b71(37, function()
local tree = b3b71[3]('source_shared_engine_tree')
local ui_common = b3b71[45]('source_engine_api_draw_ui_common')
local util_decorator = b3b71[2]('source_shared_functional_decorator')
local function dir(self, mode)
if mode then
self.node.config.dir = mode
end
return self
end
local function component(std, engine, layout)
local rows, cols = layout:match('(%d+)x(%d+)')
local node = std.node.load({})
tree.node_add(engine.dom, node, {parent=engine.current})
node.config.type = 'grid'
node.config.rows = tonumber(rows)
node.config.cols = tonumber(cols)
node.config.dir = (node.config.rows == 1 and node.config.cols > 1) and 1 or 0
local self = {
node=node,
add=util_decorator.prefix2(std, engine, ui_common.add),
add_items=util_decorator.prefix2(std, engine, ui_common.add_items),
get_items=ui_common.get_items,
get_item=ui_common.get_item,
dir=dir
}
return self
end
local P = {
component = component
}
return P
end)
b3b71[38] = r3b71(38, function()
local ui_common = b3b71[45]('source_engine_api_draw_ui_common')
local util_decorator = b3b71[2]('source_shared_functional_decorator')
local function slider_next(self, to)
local incr = to or 1
self.index = self.index + incr
if self.index == 0 then
self.index = #self.items_node
end
if self.index > #self.items_node then
self.index = 1
end
return self
end
local function slider_back(self)
return slider_next(self, -1)
end
local function apply(std, engine, self)
local index = 1
local x, y = 0, 0
local index2 = 1
local pipeline = std.ui.style(self.classlist).pipeline
while index2 <= #pipeline do
pipeline[index2](std, self.node, self.node.config.parent, engine.root)
index2 = index2 + 1
end
local hem = self.node.data.width / self.rows
local vem = self.node.data.height / self.cols
while index <= #self.items_node do
local node = self.items_node[index]
local size = self.items_size[index]
local ui = self.items_ui[node]
node.config.offset_x = x * hem
node.config.offset_y = y * vem
node.data.width = size * hem
node.data.height = vem
x = x + size
if x >= self.rows then
y = y + 1
x = 0
end
if index == self.index then
local index3 = 1
local pipeline2 = std.ui.style(self.classlist_selected).pipeline
while index3 <= #pipeline2 do
pipeline2[index3](std, node, node.config.parent, engine.root)
index3 = index3 + 1
end
end
if ui then
ui:apply()
end
index = index + 1
end
return self
end
local function component(std, engine, layout)
local rows, cols = layout:match('(%d+)x(%d+)')
if rows ~= '1' and cols ~= '1' then
error('invalid grid layout')
end
local node = std.node.load({
width = engine.current.data.width,
height = engine.current.data.height
})
local self = {
index = 1,
rows=tonumber(rows),
cols=tonumber(cols),
items_node = {},
items_size = {},
items_ui = {},
node=node,
classlist='',
classlist_selected='',
next=slider_next,
back=slider_back,
add=util_decorator.prefix2(std, engine, ui_common.add),
add_items=util_decorator.prefix2(std, engine, ui_common.add_items),
style_item_select=util_decorator.prefix1('classlist_selected', ui_common.style),
style=util_decorator.prefix1('classlist', ui_common.style),
apply=util_decorator.prefix2(std, engine, apply),
get_item=ui_common.get_item
}
if engine.root == engine.current then
node.callbacks.resize = function()
if node.config.parent ~= engine.root then
node.callbacks.resize = nil
return
end
node.data.height = engine.root.data.height
node.data.width = engine.root.data.width
self:apply()
end
end
std.node.spawn(node)
return self
end
local P = {
component = component
}
return P
end)
b3b71[39] = r3b71(39, function()
local tree = b3b71[3]('source_shared_engine_tree')
local function add(engine, self, node)
tree.css_add(engine.dom, self.func, node)
return self
end
local function add_items(engine, self, nodes)
local index = 1
while nodes and index <= #nodes do
add(engine, self, nodes[index])
index = index + 1
end
return self
end
local function remove(engine, self, node)
tree.css_del(engine.dom, self.func, node)
return self
end
local function component(engine, name, options)
local self = {
func = tree.stylesheet(engine.dom, name, options),
add = function(a, b) return add(engine, a, b) end,
add_items = function(a, b) return add_items(engine, a, b) end,
remove = function(a, b) return remove(engine, a, b) end
}
return self
end
local P = {
component = component
}
return P
end)
b3b71[40] = r3b71(40, function()
local function get_max_width(indent)
if indent <= 40 then
return 80
else
return nil
end
end
local function wrap_text(text, indent)
local max_width = get_max_width(indent)
local prefix = string.rep("  ", indent)
if not max_width then
local lines = {}
for line in text:gmatch("[^\n]+") do
table.insert(lines, prefix .. line)
end
return table.concat(lines, "\n")
end
local words = {}
for word in text:gmatch("%S+") do table.insert(words, word) end
local lines = {}
local line = ""
for _, word in ipairs(words) do
if #line + #word + 1 > max_width - indent * 2 then
table.insert(lines, prefix .. line)
line = word
else
if line == "" then
line = word
else
line = line .. " " .. word
end
end
end
if line ~= "" then table.insert(lines, prefix .. line) end
return table.concat(lines, "\n")
end
local function sanitize_key(key)
if type(key) ~= "string" then
key = tostring(key)
end
key = key:gsub("[^%w_-]", "_")
return key
end
local function should_quote(s)
if type(s) ~= "string" then return false end
if s:match("^[^%a_]") or s:match("^%d+$") then
return true
end
if s == "true" or s == "false" or s == "null" then
return false
end
return false
end
local function format_string(s, indent)
if type(s) ~= "string" then
return tostring(s)
end
local max_width = get_max_width(indent)
if s:find("\n") then
local lines = {}
for line in s:gmatch("[^\n]+") do
if max_width then
line = wrap_text(line, indent + 1)
else
line = string.rep("  ", indent + 1) .. line
end
table.insert(lines, line)
end
return "|-\n" .. table.concat(lines, "\n")
elseif max_width and #s > max_width - indent * 2 then
return ">-\n" .. wrap_text(s, indent + 1)
elseif should_quote(s) then
return string.format("%q", s)
else
return s
end
end
local function to_yaml(tbl, indent)
indent = indent or 0
local yaml = ""
local prefix = string.rep("  ", indent)
local nums = {}
local keys = {}
for k, v in pairs(tbl) do
if type(v) ~= "function" then
if type(k) == "number" then
table.insert(nums, k)
else
table.insert(keys, k)
end
end
end
table.sort(keys)
for _, k in ipairs(keys) do
local v = tbl[k]
local safe_key = sanitize_key(k)
if type(v) == "table" then
yaml = yaml .. prefix .. safe_key .. ":\n" .. to_yaml(v, indent + 1)
else
yaml = yaml .. prefix .. safe_key .. ": " .. format_string(v, indent) .. "\n"
end
end
table.sort(nums)
for _, k in ipairs(nums) do
local v = tbl[k]
if type(v) == "table" then
yaml = yaml .. prefix .. "-\n" .. to_yaml(v, indent + 1)
else
yaml = yaml .. prefix .. "- " .. format_string(v, indent) .. "\n"
end
end
return yaml
end
return {
encode = to_yaml
}
end)
b3b71[41] = r3b71(41, function()
local P = {
data={
width=1280,
height=720
},
meta={
},
config = {
offset_x = 0,
offset_y = 0
},
callbacks={
}
}
return P;
end)
b3b71[43] = r3b71(43, function()
local function is_ok(status)
return (status and 200 <= status and status < 300) or false
end
local function is_ok_header(header)
local status = tonumber(header:match('HTTP/%d.%d (%d%d%d)'))
local ok = status and is_ok(status) or false
return ok, status
end
local function is_redirect(status)
return (status and 300 <= status and status < 400) or false
end
local function get_content(response)
local header, body = response:match("^(.-\r\n\r\n)(.*)")
if not header or not body then return nil end
local content_length = tonumber(header:match("Content%-Length:%s*(%d+)"))
if not content_length then return nil end
if #body < content_length then return nil end
local content = body:sub(1, content_length)
return content
end
local function get_user_agent()
return 'Ginga (GlyOS;SmartTv/Linux)'
end
local function create_request(method, uri)
local self = {
body_content = '',
header_list = {},
header_dict = {},
header_imutable = {},
print_http_status = true
}
self.add_body_content = function (body)
self.body_content = self.body_content..(body or '')
return self
end
self.add_imutable_header = function (header, value, cond)
if cond == false then return self end
if self.header_imutable[header] == nil then
self.header_list[#self.header_list + 1] = header
self.header_dict[header] = value
elseif self.header_imutable[header] == false then
self.header_dict[header] = value
end
self.header_imutable[header] = true
return self
end
self.add_mutable_header = function (header, value, cond)
if cond == false then return self end
if self.header_imutable[header] == nil then
self.header_list[#self.header_list + 1] = header
self.header_imutable[header] = false
self.header_dict[header] = value
end
return self
end
self.add_custom_headers = function(header_list, header_dict)
local index = 1
while header_list and #header_list >= index do
local header = header_list[index]
local value = header_dict[header]
if self.header_imutable[header] == nil then
self.header_list[#self.header_list + 1] = header
self.header_imutable[header] = false
self.header_dict[header] = value
elseif self.header_imutable[header] == false then
self.header_dict[header] = value
end
index = index + 1
end
return self
end
self.not_status = function()
self.print_http_status = false
return self
end
self.to_http_protocol = function ()
local index = 1
local request = method..' '..uri..' HTTP/1'..'.1\r\n'
while index <= #self.header_list do
local header = self.header_list[index]
local value = self.header_dict[header]
request = request..header..': '..value..'\r\n'
index = index + 1
end
request = request..'\r\n'
if method ~= 'GET' and method ~= 'HEAD' and #self.body_content > 0 then
request = request..self.body_content..'\r\n\r\n'
end
return request, function() end
end
self.to_curl_cmd = function ()
local index = 1
local request = 'curl -L -'..'-silent -'..'-insecure '
if self.print_http_status then
request = request..'-w "\n%{http_code}" '
end
if method == 'HEAD' then
request = request..'-'..'-HEAD '
else
request = request..'-X '..method..' '
end
while index <= #self.header_list do
local header = self.header_list[index]
local value = self.header_dict[header]
request = request..'-H "'..header..': '..value..'" '
index = index + 1
end
if method ~= 'GET' and method ~= 'HEAD' and #self.body_content > 0 then
request = request..'-d \''..self.body_content..'\' '
end
request = request..uri
return request, function() end
end
self.to_wget_cmd = function ()
local request = 'wget -'..'-quiet -'..'-output-document=-'
if method == 'HEAD' then
request = request..' -'..'-method=HEAD'
elseif method ~= 'GET' then
request = request..' -'..'-method='..method
end
for index, header in ipairs(self.header_list) do
local value = self.header_dict[header]
if value then
local escaped_value = value:gsub('"', '\\"')
request = request..' -'..'-header="'..header..': '..escaped_value..'"'
end
end
if method ~= 'GET' and method ~= 'HEAD' and #self.body_content > 0 then
local escaped_body = self.body_content:gsub('"', '\\"')
request = request..' -'..'-body-data="'..escaped_body..'"'
end
request = request..' '..uri
return request, function() end
end
return self
end
return {
is_ok=is_ok,
is_ok_header=is_ok_header,
is_redirect=is_redirect,
get_content=get_content,
get_user_agent=get_user_agent,
create_request=create_request
}
end)
b3b71[44] = r3b71(44, function()
local function percent_encode(str)
return (str:gsub('[^A-Za-z0-9%-_%.~]', function(c)
return string.format('%%%02X', string.byte(c))
end))
end
local function search_param(param_list, param_dict)
local index, params = 1, ''
while param_list and param_dict and index <= #param_list do
local param = param_list[index]
local value = param_dict[param]
if #params == 0 then
params = params..'?'
else
params = params..'&'
end
params = params..percent_encode(param)..'='..percent_encode(value or '')
index = index + 1
end
return params
end
local P = {
search_param = search_param
}
return P
end)
b3b71[45] = r3b71(45, function()
local tree = b3b71[3]('source_shared_engine_tree')
local function add(std, engine, self, application, options)
if not application then return self end
local node = application.node or std.node.load(application)
local size = (type(options) == 'number' and options) or (options or {}).span
local after = options ~= size and (options or {}).after
local offset = options ~= size and (options or {}).offset
tree.node_add(engine.dom, node, {
parent = self.node,
offset = offset,
after = after,
size = size
})
return self
end
local function add_items(std, engine, self, applications)
local index = 1
while applications and index <= #applications do
add(std, engine, self, applications[index])
index = index + 1
end
return self
end
local function get_item(self, id)
return self.node.childs[id]
end
local function get_items(self)
return self.node.childs
end
local P = {
add=add,
get_item=get_item,
get_items=get_items,
add_items=add_items,
}
return P
end)
return m3b71()
