@gamely/gly-engine-lite 0.3.7 → 0.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/main.lua +231 -100
  2. package/package.json +1 -1
package/dist/main.lua CHANGED
@@ -1,37 +1,37 @@
1
- local b25ba = {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}
2
- local r25ba = function(i, f)
1
+ local b2967 = {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}
2
+ local r2967 = function(i, f)
3
3
  return function()
4
4
  local c = f()
5
- b25ba[i] = function() return c end
5
+ b2967[i] = function() return c end
6
6
  return c
7
7
  end
8
8
  end
9
9
  local math = ((function() local x, y = pcall(require, 'math'); return x and y end)()) or _G.math
10
- local function m25ba()
11
- local version = b25ba[1]('source_version')
12
- local loadcore = b25ba[2]('source_shared_engine_loadcore')
13
- local loadgame = b25ba[3]('source_shared_engine_loadgame')
14
- local engine_encoder = b25ba[4]('source_engine_api_data_encoder')
15
- local engine_game = b25ba[5]('source_engine_api_system_app')
16
- local engine_hash = b25ba[6]('source_engine_api_data_hash')
17
- local engine_http = b25ba[7]('source_engine_api_io_http')
18
- local engine_i18n = b25ba[8]('source_engine_api_data_i18n')
19
- local engine_key = b25ba[9]('source_engine_api_system_key')
20
- local engine_env = b25ba[10]('source_engine_api_system_getenv')
21
- local engine_log = b25ba[11]('source_engine_api_debug_log')
22
- local engine_math = b25ba[12]('source_engine_api_math_basic')
23
- local engine_math_clib = b25ba[13]('source_engine_api_math_clib')
24
- local engine_math_random = b25ba[14]('source_engine_api_math_random')
25
- local engine_array = b25ba[15]('source_engine_api_data_array')
26
- local engine_media = b25ba[16]('source_engine_api_io_media')
27
- local engine_api_draw_fps = b25ba[17]('source_engine_api_draw_fps')
28
- local engine_api_draw_text = b25ba[18]('source_engine_api_draw_text')
29
- local engine_api_draw_poly = b25ba[19]('source_engine_api_draw_poly')
30
- local engine_raw_memory = b25ba[20]('source_engine_api_raw_memory')
31
- local callback_http = b25ba[21]('source_engine_protocol_http_callback')
32
- local application_default = b25ba[22]('source_shared_var_object_root')
33
- local color = b25ba[23]('source_engine_api_system_color')
34
- local std = b25ba[24]('source_shared_var_object_std')
10
+ local function m2967()
11
+ local version = b2967[1]('source_version')
12
+ local loadcore = b2967[2]('source_shared_engine_loadcore')
13
+ local loadgame = b2967[3]('source_shared_engine_loadgame')
14
+ local engine_encoder = b2967[4]('source_engine_api_data_encoder')
15
+ local engine_game = b2967[5]('source_engine_api_system_app')
16
+ local engine_hash = b2967[6]('source_engine_api_data_hash')
17
+ local engine_http = b2967[7]('source_engine_api_io_http')
18
+ local engine_i18n = b2967[8]('source_engine_api_data_i18n')
19
+ local engine_key = b2967[9]('source_engine_api_system_key')
20
+ local engine_env = b2967[10]('source_engine_api_system_getenv')
21
+ local engine_log = b2967[11]('source_engine_api_debug_log')
22
+ local engine_math = b2967[12]('source_engine_api_math_basic')
23
+ local engine_math_clib = b2967[13]('source_engine_api_math_clib')
24
+ local engine_math_random = b2967[14]('source_engine_api_math_random')
25
+ local engine_array = b2967[15]('source_engine_api_data_array')
26
+ local engine_media = b2967[16]('source_engine_api_io_media')
27
+ local engine_api_draw_fps = b2967[17]('source_engine_api_draw_fps')
28
+ local engine_api_draw_text = b2967[18]('source_engine_api_draw_text')
29
+ local engine_api_draw_poly = b2967[19]('source_engine_api_draw_poly')
30
+ local engine_raw_memory = b2967[20]('source_engine_api_raw_memory')
31
+ local callback_http = b2967[21]('source_engine_protocol_http_callback')
32
+ local application_default = b2967[22]('source_shared_var_object_root')
33
+ local color = b2967[23]('source_engine_api_system_color')
34
+ local std = b2967[24]('source_shared_var_object_std')
35
35
  local application = application_default
36
36
  local engine = {
37
37
  keyboard = function(a, b, c, d) end,
@@ -193,12 +193,12 @@ version=version
193
193
  }
194
194
  return P
195
195
  end
196
- b25ba[1] = r25ba(1, function()
197
- return '0.3.7'
196
+ b2967[1] = r2967(1, function()
197
+ return '0.3.8'
198
198
  end)
199
- b25ba[2] = r25ba(2, function()
200
- local zeebo_pipeline = b25ba[25]('source_shared_functional_pipeline')
201
- local requires = b25ba[26]('source_shared_string_dsl_requires')
199
+ b2967[2] = r2967(2, function()
200
+ local zeebo_pipeline = b2967[25]('source_shared_functional_pipeline')
201
+ local requires = b2967[26]('source_shared_string_dsl_requires')
202
202
  local function step_install_libsys(self, lib_name, library, custom, is_system)
203
203
  if not is_system then return end
204
204
  local ok, msg = pcall(function()
@@ -279,9 +279,9 @@ setup = setup
279
279
  }
280
280
  return P
281
281
  end)
282
- b25ba[3] = r25ba(3, function()
283
- local eval_file = b25ba[27]('source_shared_string_eval_file')
284
- local eval_code = b25ba[28]('source_shared_string_eval_code')
282
+ b2967[3] = r2967(3, function()
283
+ local eval_file = b2967[27]('source_shared_string_eval_file')
284
+ local eval_code = b2967[28]('source_shared_string_eval_code')
285
285
  local has_io_open = io and io.open
286
286
  local function normalize(app, base)
287
287
  if not app then return nil end
@@ -355,7 +355,7 @@ script = script
355
355
  }
356
356
  return P
357
357
  end)
358
- b25ba[4] = r25ba(4, function()
358
+ b2967[4] = r2967(4, function()
359
359
  local function install(std, engine, library, name)
360
360
  std = std or {}
361
361
  std[name] = {
@@ -369,7 +369,7 @@ install=install
369
369
  }
370
370
  return P
371
371
  end)
372
- b25ba[5] = r25ba(5, function()
372
+ b2967[5] = r2967(5, function()
373
373
  local function reset(std, engine)
374
374
  if std.node then
375
375
  return function()
@@ -418,7 +418,7 @@ install=install
418
418
  }
419
419
  return P
420
420
  end)
421
- b25ba[6] = r25ba(6, function()
421
+ b2967[6] = r2967(6, function()
422
422
  local function djb2(digest)
423
423
  local index = 1
424
424
  local hash = 5381
@@ -441,8 +441,8 @@ install = install
441
441
  }
442
442
  return P
443
443
  end)
444
- b25ba[7] = r25ba(7, function()
445
- local zeebo_pipeline = b25ba[25]('source_shared_functional_pipeline')
444
+ b2967[7] = r2967(7, function()
445
+ local zeebo_pipeline = b2967[25]('source_shared_functional_pipeline')
446
446
  local function json(self)
447
447
  self.options['json'] = true
448
448
  return self
@@ -608,7 +608,7 @@ install=install
608
608
  }
609
609
  return P
610
610
  end)
611
- b25ba[8] = r25ba(8, function()
611
+ b2967[8] = r2967(8, function()
612
612
  local language = 'en-US'
613
613
  local language_default = 'en-US'
614
614
  local language_list = {}
@@ -699,7 +699,7 @@ install=install
699
699
  }
700
700
  return P
701
701
  end)
702
- b25ba[9] = r25ba(9, function()
702
+ b2967[9] = r2967(9, function()
703
703
  local function real_key(std, engine, rkey, rvalue)
704
704
  local value = (rvalue == 1 or rvalue == true) or false
705
705
  local key = engine.key_bindings[rkey] or (std.key.axis[rkey] and rkey)
@@ -748,7 +748,7 @@ return {
748
748
  install = install
749
749
  }
750
750
  end)
751
- b25ba[10] = r25ba(10, function()
751
+ b2967[10] = r2967(10, function()
752
752
  local function setenv(engine)
753
753
  return function(varname, value)
754
754
  if engine.root ~= engine.current then
@@ -791,53 +791,66 @@ install = install
791
791
  }
792
792
  return P
793
793
  end)
794
- b25ba[11] = r25ba(11, function()
795
- local util_decorator = b25ba[29]('source_shared_functional_decorator')
796
- local logging_types = {
797
- 'none', 'fatal', 'error', 'warn', 'debug', 'info'
798
- }
799
- local function level(engine, lpf, lpn, level)
800
- local l = lpf[level] or lpn[level] or level
801
- if type(l) ~= 'number' or l <= 0 or l > #logging_types then
794
+ b2967[11] = r2967(11, function()
795
+ local yaml = b2967[29]('source_shared_string_encode_yaml')
796
+ local levels = { none = 0, fatal = 1, error = 2, warn = 3, info = 4, debug = 5, trace = 6}
797
+ local function printer(engine, printers, func_a, func_b)
798
+ local fn_a = func_a and printers[func_a]
799
+ local fn_b = func_b and printers[func_b]
800
+ local func = fn_a or fn_b or function() end
801
+ local level = levels[func_a] or 7
802
+ return function (...)
803
+ local msgs = {...}
804
+ local count = #msgs
805
+ if level <= engine.loglevel then
806
+ local content = ''
807
+ for i = 1, count do
808
+ local v = msgs[i]
809
+ local t = type(v)
810
+ if t == 'table' then
811
+ content = content..'\n'..yaml.encode(v)..'\n'
812
+ elseif t ~= 'function' then
813
+ local add_space = i ~= count and i > 1 and content:sub(-1) ~= '\n'
814
+ local prefix = add_space and ' ' or ''
815
+ content = content..prefix..tostring(v)
816
+ end
817
+ end
818
+ func(content)
819
+ end
820
+ end
821
+ end
822
+ local function level(engine)
823
+ return function(n)
824
+ local lv = levels[n] or (type(n) == 'number' and n) or -1
825
+ if lv < 0 or 6 < lv then
802
826
  error('logging level not exist: '..tostring(level))
803
827
  end
804
- engine.loglevel = l
828
+ engine.loglevel = lv
805
829
  end
806
- local function init(std, engine, printers)
807
- local index = 1
808
- local level_per_func = {}
809
- local level_per_name = {}
810
- while index <= #logging_types do
811
- local ltype = logging_types[index]
812
- local lfunc = function() end
813
- if index > 1 and printers[ltype] then
814
- lfunc = (function (level)
815
- return function(message)
816
- if engine.loglevel >= level then
817
- printers[ltype](message)
818
- end
819
- end
820
- end)(index - 1)
821
- end
822
- level_per_func[lfunc] = index - 1
823
- level_per_name[ltype] = index - 1
824
- std.log[ltype] = lfunc
825
- index = index + 1
826
830
  end
827
- std.log.level = util_decorator.prefix3(engine, level_per_func, level_per_name, level)
831
+ local function init(std, engine)
832
+ return function(printers)
833
+ std.log.fatal = printer(engine, printers, 'fatal', 'error')
834
+ std.log.error = printer(engine, printers, 'error')
835
+ std.log.warn = printer(engine, printers, 'warn')
836
+ std.log.info = printer(engine, printers, 'info')
837
+ std.log.debug = printer(engine, printers, 'debug', 'info')
838
+ std.log.trace = printer(engine, printers, 'trace', 'info')
839
+ end
828
840
  end
829
841
  local function install(std, engine, printers)
830
842
  std.log = std.log or {}
831
- engine.loglevel = #logging_types
832
- std.log.init = util_decorator.prefix2(std, engine, init)
843
+ std.log.init = init(std, engine)
844
+ std.log.level = level(engine)
833
845
  std.log.init(printers)
846
+ std.log.level('debug')
834
847
  end
835
848
  local P = {
836
849
  install = install
837
850
  }
838
851
  return P
839
852
  end)
840
- b25ba[12] = r25ba(12, function()
853
+ b2967[12] = r2967(12, function()
841
854
  local function abs(value)
842
855
  if value < 0 then
843
856
  return -value
@@ -935,7 +948,7 @@ install = install
935
948
  }
936
949
  return P
937
950
  end)
938
- b25ba[13] = r25ba(13, function()
951
+ b2967[13] = r2967(13, function()
939
952
  local function install(std)
940
953
  assert(math and (1/2 ~= 0))
941
954
  std.math = std.math or {}
@@ -970,7 +983,7 @@ install = install
970
983
  }
971
984
  return P
972
985
  end)
973
- b25ba[14] = r25ba(14, function()
986
+ b2967[14] = r2967(14, function()
974
987
  local function install(std)
975
988
  assert(math and (1/2 ~= 0))
976
989
  std.math = std.math or {}
@@ -986,8 +999,8 @@ install = install
986
999
  }
987
1000
  return P
988
1001
  end)
989
- b25ba[15] = r25ba(15, function()
990
- local util_decorator = b25ba[29]('source_shared_functional_decorator')
1002
+ b2967[15] = r2967(15, function()
1003
+ local util_decorator = b2967[31]('source_shared_functional_decorator')
991
1004
  local function array_map(array, func)
992
1005
  local res = {}
993
1006
  local index = 1
@@ -1147,7 +1160,7 @@ install = install
1147
1160
  }
1148
1161
  return P
1149
1162
  end)
1150
- b25ba[16] = r25ba(16, function()
1163
+ b2967[16] = r2967(16, function()
1151
1164
  local function media_create(node, channels, handler)
1152
1165
  local decorator = function(func)
1153
1166
  func = func or function() end
@@ -1193,7 +1206,7 @@ install=install
1193
1206
  }
1194
1207
  return P
1195
1208
  end)
1196
- b25ba[17] = r25ba(17, function()
1209
+ b2967[17] = r2967(17, function()
1197
1210
  local function draw_fps(std, engine, show, pos_x, pos_y)
1198
1211
  if show < 1 then return end
1199
1212
  local x = engine.current.config.offset_x + pos_x
@@ -1241,7 +1254,7 @@ install=install
1241
1254
  }
1242
1255
  return P
1243
1256
  end)
1244
- b25ba[18] = r25ba(18, function()
1257
+ b2967[18] = r2967(18, function()
1245
1258
  local function text_put(std, engine, font_previous)
1246
1259
  return function(pos_x, pos_y, text, size)
1247
1260
  size = size or 2
@@ -1273,7 +1286,7 @@ install=install
1273
1286
  }
1274
1287
  return P
1275
1288
  end)
1276
- b25ba[19] = r25ba(19, function()
1289
+ b2967[19] = r2967(19, function()
1277
1290
  local function decorator_poo(object, func)
1278
1291
  if not object or not func then return func end
1279
1292
  return function(a, b, c, d)
@@ -1379,7 +1392,7 @@ install=install
1379
1392
  }
1380
1393
  return P
1381
1394
  end)
1382
- b25ba[20] = r25ba(20, function()
1395
+ b2967[20] = r2967(20, function()
1383
1396
  local memory_dict_unload = {}
1384
1397
  local memory_dict = {}
1385
1398
  local memory_list = {}
@@ -1433,9 +1446,9 @@ install=install
1433
1446
  }
1434
1447
  return P
1435
1448
  end)
1436
- b25ba[21] = r25ba(21, function()
1437
- local str_http = b25ba[31]('source_shared_string_encode_http')
1438
- local str_url = b25ba[32]('source_shared_string_encode_url')
1449
+ b2967[21] = r2967(21, function()
1450
+ local str_http = b2967[32]('source_shared_string_encode_http')
1451
+ local str_url = b2967[33]('source_shared_string_encode_url')
1439
1452
  local callbacks = {
1440
1453
  ['async-promise'] = function(self)
1441
1454
  return self:promise()
@@ -1504,7 +1517,7 @@ func = native_http_callback
1504
1517
  }
1505
1518
  return P
1506
1519
  end)
1507
- b25ba[22] = r25ba(22, function()
1520
+ b2967[22] = r2967(22, function()
1508
1521
  local P = {
1509
1522
  data={
1510
1523
  width=1280,
@@ -1533,7 +1546,7 @@ callbacks={
1533
1546
  }
1534
1547
  return P;
1535
1548
  end)
1536
- b25ba[23] = r25ba(23, function()
1549
+ b2967[23] = r2967(23, function()
1537
1550
  local function install(std)
1538
1551
  std.color = std.color or {}
1539
1552
  std.color.white = 0xFFFFFFFF
@@ -1567,7 +1580,7 @@ install = install
1567
1580
  }
1568
1581
  return P
1569
1582
  end)
1570
- b25ba[24] = r25ba(24, function()
1583
+ b2967[24] = r2967(24, function()
1571
1584
  local P = {
1572
1585
  milis = 0,
1573
1586
  delta = 0,
@@ -1634,7 +1647,7 @@ any=false
1634
1647
  }
1635
1648
  return P;
1636
1649
  end)
1637
- b25ba[25] = r25ba(25, function()
1650
+ b2967[25] = r2967(25, function()
1638
1651
  local function pipe(self)
1639
1652
  return function()
1640
1653
  self:run()
@@ -1683,7 +1696,7 @@ run=run
1683
1696
  }
1684
1697
  return P
1685
1698
  end)
1686
- b25ba[26] = r25ba(26, function()
1699
+ b2967[26] = r2967(26, function()
1687
1700
  local function encode(dsl_string)
1688
1701
  local spec = {
1689
1702
  list = {},
@@ -1731,7 +1744,7 @@ should_import = should_import
1731
1744
  }
1732
1745
  return P
1733
1746
  end)
1734
- b25ba[27] = r25ba(27, function()
1747
+ b2967[27] = r2967(27, function()
1735
1748
  local function script(src)
1736
1749
  local ok, app = false, nil
1737
1750
  if require then
@@ -1756,7 +1769,7 @@ script = script,
1756
1769
  }
1757
1770
  return P
1758
1771
  end)
1759
- b25ba[28] = r25ba(28, function()
1772
+ b2967[28] = r2967(28, function()
1760
1773
  local function script(src)
1761
1774
  local loader = loadstring or load
1762
1775
  if not loader then
@@ -1776,7 +1789,125 @@ script = script,
1776
1789
  }
1777
1790
  return P
1778
1791
  end)
1779
- b25ba[29] = r25ba(29, function()
1792
+ b2967[29] = r2967(29, function()
1793
+ local function get_max_width(indent)
1794
+ if indent <= 40 then
1795
+ return 80
1796
+ else
1797
+ return nil
1798
+ end
1799
+ end
1800
+ local function wrap_text(text, indent)
1801
+ local max_width = get_max_width(indent)
1802
+ local prefix = string.rep(" ", indent)
1803
+ if not max_width then
1804
+ local lines = {}
1805
+ for line in text:gmatch("[^\n]+") do
1806
+ table.insert(lines, prefix .. line)
1807
+ end
1808
+ return table.concat(lines, "\n")
1809
+ end
1810
+ local words = {}
1811
+ for word in text:gmatch("%S+") do table.insert(words, word) end
1812
+ local lines = {}
1813
+ local line = ""
1814
+ for _, word in ipairs(words) do
1815
+ if #line + #word + 1 > max_width - indent * 2 then
1816
+ table.insert(lines, prefix .. line)
1817
+ line = word
1818
+ else
1819
+ if line == "" then
1820
+ line = word
1821
+ else
1822
+ line = line .. " " .. word
1823
+ end
1824
+ end
1825
+ end
1826
+ if line ~= "" then table.insert(lines, prefix .. line) end
1827
+ return table.concat(lines, "\n")
1828
+ end
1829
+ local function sanitize_key(key)
1830
+ if type(key) ~= "string" then
1831
+ key = tostring(key)
1832
+ end
1833
+ key = key:gsub("[^%w_-]", "_")
1834
+ return key
1835
+ end
1836
+ local function should_quote(s)
1837
+ if type(s) ~= "string" then return false end
1838
+ if s:match("^[^%a_]") or s:match("^%d+$") then
1839
+ return true
1840
+ end
1841
+ if s == "true" or s == "false" or s == "null" then
1842
+ return false
1843
+ end
1844
+ return false
1845
+ end
1846
+ local function format_string(s, indent)
1847
+ if type(s) ~= "string" then
1848
+ return tostring(s)
1849
+ end
1850
+ local max_width = get_max_width(indent)
1851
+ if s:find("\n") then
1852
+ local lines = {}
1853
+ for line in s:gmatch("[^\n]+") do
1854
+ if max_width then
1855
+ line = wrap_text(line, indent + 1)
1856
+ else
1857
+ line = string.rep(" ", indent + 1) .. line
1858
+ end
1859
+ table.insert(lines, line)
1860
+ end
1861
+ return "|-\n" .. table.concat(lines, "\n")
1862
+ elseif max_width and #s > max_width - indent * 2 then
1863
+ return ">-\n" .. wrap_text(s, indent + 1)
1864
+ elseif should_quote(s) then
1865
+ return string.format("%q", s)
1866
+ else
1867
+ return s
1868
+ end
1869
+ end
1870
+ local function to_yaml(tbl, indent)
1871
+ indent = indent or 0
1872
+ local yaml = ""
1873
+ local prefix = string.rep(" ", indent)
1874
+ local nums = {}
1875
+ local keys = {}
1876
+ for k, v in pairs(tbl) do
1877
+ if type(v) ~= "function" then
1878
+ if type(k) == "number" then
1879
+ table.insert(nums, k)
1880
+ else
1881
+ table.insert(keys, k)
1882
+ end
1883
+ end
1884
+ end
1885
+ table.sort(keys)
1886
+ for _, k in ipairs(keys) do
1887
+ local v = tbl[k]
1888
+ local safe_key = sanitize_key(k)
1889
+ if type(v) == "table" then
1890
+ yaml = yaml .. prefix .. safe_key .. ":\n" .. to_yaml(v, indent + 1)
1891
+ else
1892
+ yaml = yaml .. prefix .. safe_key .. ": " .. format_string(v, indent) .. "\n"
1893
+ end
1894
+ end
1895
+ table.sort(nums)
1896
+ for _, k in ipairs(nums) do
1897
+ local v = tbl[k]
1898
+ if type(v) == "table" then
1899
+ yaml = yaml .. prefix .. "-\n" .. to_yaml(v, indent + 1)
1900
+ else
1901
+ yaml = yaml .. prefix .. "- " .. format_string(v, indent) .. "\n"
1902
+ end
1903
+ end
1904
+ return yaml
1905
+ end
1906
+ return {
1907
+ encode = to_yaml
1908
+ }
1909
+ end)
1910
+ b2967[31] = r2967(31, function()
1780
1911
  local function decorator_prefix3(zig, zag, zom, func)
1781
1912
  return function (a, b, c, d, e, f)
1782
1913
  return func(zig, zag, zom, a, b, c, d, e, f)
@@ -1833,7 +1964,7 @@ prefix1_t = table_prefix1
1833
1964
  }
1834
1965
  return P
1835
1966
  end)
1836
- b25ba[31] = r25ba(31, function()
1967
+ b2967[32] = r2967(32, function()
1837
1968
  local function is_ok(status)
1838
1969
  return (status and 200 <= status and status < 300) or false
1839
1970
  end
@@ -1979,7 +2110,7 @@ get_user_agent=get_user_agent,
1979
2110
  create_request=create_request
1980
2111
  }
1981
2112
  end)
1982
- b25ba[32] = r25ba(32, function()
2113
+ b2967[33] = r2967(33, function()
1983
2114
  local function search_param(param_list, param_dict)
1984
2115
  local index, params = 1, ''
1985
2116
  while param_list and param_dict and index <= #param_list do
@@ -2000,4 +2131,4 @@ search_param = search_param
2000
2131
  }
2001
2132
  return P
2002
2133
  end)
2003
- return m25ba()
2134
+ return m2967()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gamely/gly-engine-lite",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "author": "RodrigoDornelles",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://docs.gamely.com.br",