From b56b681953f7ceb98c20ed5ed4f570372e1a136f Mon Sep 17 00:00:00 2001 From: RodrigoDornelles Date: Fri, 1 Nov 2024 13:30:18 -0300 Subject: [PATCH 1/5] feat: add cli command fs-gamefill #109 --- src/cli/commands/fs.lua | 8 +++++++- src/cli/main.lua | 4 ++++ src/lib/cli/filler.lua | 31 +++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/lib/cli/filler.lua diff --git a/src/cli/commands/fs.lua b/src/cli/commands/fs.lua index 3ec2d79..588b713 100644 --- a/src/cli/commands/fs.lua +++ b/src/cli/commands/fs.lua @@ -1,4 +1,5 @@ local zeebo_fs = require('src/lib/cli/fs') +local zeebo_filler = require('src/lib/cli/filler') local function replace(args) local file_in = io.open(args.file,'r') @@ -95,12 +96,17 @@ local function luaconf(args) return true end +local function game_fill(args) + return zeebo_filler.put(args.dist, tonumber(args.size)) +end + local P = { ['fs-copy'] = copy, ['fs-xxd-i'] = vim_xxd_i, ['fs-luaconf'] = luaconf, ['fs-replace'] = replace, - ['fs-download'] = download + ['fs-download'] = download, + ['fs-gamefill'] = game_fill } return P diff --git a/src/cli/main.lua b/src/cli/main.lua index 0e8f3e1..a43e9e6 100644 --- a/src/cli/main.lua +++ b/src/cli/main.lua @@ -78,6 +78,10 @@ local command = zeebo_argparse.from(arg) .add_next_value('url', {required=true}) .add_next_value('dist', {required=true}) -- + .add_subcommand('fs-gamefill', commands_fs) + .add_next_value('dist', {required=true}) + .add_next_value('size', {required=true}) + -- .add_subcommand('cli-build', commands_cli) .add_option_get('dist', {default='./dist/'}) .add_subcommand('cli-test', commands_cli) diff --git a/src/lib/cli/filler.lua b/src/lib/cli/filler.lua new file mode 100644 index 0000000..eb25397 --- /dev/null +++ b/src/lib/cli/filler.lua @@ -0,0 +1,31 @@ +local template_prefix = '-'..'-GLYSTART\n' +local template_suffix = '\n-'..'-GLYEND' +local template = 'return {meta={title=\'G\',author=\'G\',version=\'0.0.0\'},callbacks={draw=function(s) s.draw.rect(0,8,8,8,8) end}}' + +local function put(dest, size) + local index = 0 + local template_size = #(template..template_prefix..template_suffix) + local padding_size = size - template_size + + if padding_size < 0 then + return false, 'minimal size: '..template_size..' bytes.' + end + + local padding = string.rep('\n', padding_size) + local dest_file, dest_error = io.open(dest, 'wb') + + if not dest_file then + return false, dest_error + end + + dest_file:write(template_prefix..template..padding..template_suffix) + dest_file:close() + + return true +end + +local P = { + put=put +} + +return P From b94cc3ea797b4bd66c9df5f2f4b7af7a9912c821 Mon Sep 17 00:00:00 2001 From: RodrigoDornelles Date: Fri, 1 Nov 2024 16:05:42 -0300 Subject: [PATCH 2/5] fix: wget not merged with errors on bundler --- src/lib/util/http.lua | 61 ++++++++++--------------------------------- 1 file changed, 14 insertions(+), 47 deletions(-) diff --git a/src/lib/util/http.lua b/src/lib/util/http.lua index 8cdf857..2ca12ab 100644 --- a/src/lib/util/http.lua +++ b/src/lib/util/http.lua @@ -128,20 +128,20 @@ local function create_request(method, uri) if method == 'HEAD' then table.insert(parts, '-'..'-method=HEAD') elseif method ~= 'GET' then - table.insert(parts, '-'..'-method=' .. method) + table.insert(parts, '-'..'-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('"', '\\"') - table.insert(parts, '-'..'-header="' .. header .. ': ' .. escaped_value .. '"') + table.insert(parts, '-'..'-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('"', '\\"') - table.insert(parts, '-'..'-body-data="' .. escaped_body .. '"') + table.insert(parts, '-'..'-body-data="'..escaped_body..'"') end table.insert(parts, uri) @@ -152,62 +152,29 @@ local function create_request(method, uri) end self.to_wget_cmd = function () - local parts = {'wget -'..'-quiet -'..'-output-document=-'} - - if method == 'HEAD' then - table.insert(parts, '-'..'-method=HEAD') - elseif method ~= 'GET' then - table.insert(parts, '-'..'-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('"', '\\"') - table.insert(parts, '-'..'-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('"', '\\"') - table.insert(parts, '-'..'-body-data="' .. escaped_body .. '"') - end - - table.insert(parts, uri) - - local request = table.concat(parts, ' ') - - self = nil - return request, function() end - end - - self.to_wget_cmd = function () - local parts = {'wget --quiet --output-document=-'} - + local request = 'wget -'..'-quiet -'..'-output-document=-' + if method == 'HEAD' then - table.insert(parts, '--method=HEAD') + request = request..' -'..'-method=HEAD' elseif method ~= 'GET' then - table.insert(parts, '--method=' .. method) + 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('"', '\\"') - table.insert(parts, '--header="' .. header .. ': ' .. escaped_value .. '"') + 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('"', '\\"') - table.insert(parts, '--body-data="' .. escaped_body .. '"') + request = request..' -'..'-body-data="'..escaped_body..'"' end - - table.insert(parts, uri) - - local request = table.concat(parts, ' ') - - self = nil + + request = request..' '..uri + return request, function() end end From 192b960090077fe6985b930f3213752ba477a531 Mon Sep 17 00:00:00 2001 From: RodrigoDornelles Date: Fri, 1 Nov 2024 16:31:40 -0300 Subject: [PATCH 3/5] feat: add command tool-package-del --- .github/workflows/CI.yml | 2 +- src/cli/commands/fs.lua | 8 +--- src/cli/commands/info.lua | 2 +- src/cli/commands/tools.lua | 13 ++++++- src/cli/main.lua | 12 ++++-- src/lib/cli/bundler.lua | 2 +- src/lib/cli/package.lua | 78 ++++++++++++++++++++++++++++++++++++++ tools/ci_luau-analyze.lua | 2 + 8 files changed, 104 insertions(+), 15 deletions(-) create mode 100644 src/lib/cli/package.lua diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 7be6745..8c2b548 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -60,7 +60,7 @@ jobs: strategy: fail-fast: false matrix: - core: ['native'] + core: ['native', 'love'] steps: - uses: actions/checkout@master diff --git a/src/cli/commands/fs.lua b/src/cli/commands/fs.lua index 588b713..3ec2d79 100644 --- a/src/cli/commands/fs.lua +++ b/src/cli/commands/fs.lua @@ -1,5 +1,4 @@ local zeebo_fs = require('src/lib/cli/fs') -local zeebo_filler = require('src/lib/cli/filler') local function replace(args) local file_in = io.open(args.file,'r') @@ -96,17 +95,12 @@ local function luaconf(args) return true end -local function game_fill(args) - return zeebo_filler.put(args.dist, tonumber(args.size)) -end - local P = { ['fs-copy'] = copy, ['fs-xxd-i'] = vim_xxd_i, ['fs-luaconf'] = luaconf, ['fs-replace'] = replace, - ['fs-download'] = download, - ['fs-gamefill'] = game_fill + ['fs-download'] = download } return P diff --git a/src/cli/commands/info.lua b/src/cli/commands/info.lua index ef347af..2092566 100644 --- a/src/cli/commands/info.lua +++ b/src/cli/commands/info.lua @@ -43,7 +43,7 @@ local help_message = "Available commands:\n" .."- To run a game: ./cli.sh run ./examples/asteroids/game.lua " .. "-" .. "-core repl\n" .."- To display metadata: ./cli.sh meta ./examples/asteroids/game.lua\n" -local version_message = '0.0.9' +local version_message = '0.0.10' local function help() return true, help_message diff --git a/src/cli/commands/tools.lua b/src/cli/commands/tools.lua index 0c13119..423fcb6 100644 --- a/src/cli/commands/tools.lua +++ b/src/cli/commands/tools.lua @@ -1,5 +1,7 @@ local zeebo_compiler = require('src/lib/cli/compiler') local zeebo_bundler = require('src/lib/cli/bundler') +local zeebo_package = require('src/lib/cli/package') +local zeebo_filler = require('src/lib/cli/filler') local zeebo_fs = require('src/lib/cli/fs') local function bundler(args) @@ -57,13 +59,22 @@ local function haxe_build(args) return true end +local function package_del(args) + return zeebo_package.del(args.file, args.module) +end + +local function template_fill(args) + return zeebo_filler.put(args.file, tonumber(args.size)) +end local P = { bundler = bundler, compiler = compiler, ['tool-haxe-build'] = haxe_build, ['tool-love-zip'] = love_zip, - ['tool-love-exe'] = love_exe + ['tool-love-exe'] = love_exe, + ['tool-package-del'] = package_del, + ['tool-template-fill'] = template_fill } return P diff --git a/src/cli/main.lua b/src/cli/main.lua index a43e9e6..1850cf6 100644 --- a/src/cli/main.lua +++ b/src/cli/main.lua @@ -54,6 +54,14 @@ local command = zeebo_argparse.from(arg) .add_next_value('file', {required=true}) .add_option_get('dist', {required=true}) -- + .add_subcommand('tool-package-del', commands_tools) + .add_next_value('file', {required=true}) + .add_next_value('module', {required=true}) + -- + .add_subcommand('tool-template-fill', commands_tools) + .add_next_value('file', {required=true}) + .add_next_value('size', {required=true}) + -- .add_subcommand('fs-copy', commands_fs) .add_next_value('file', {required=true}) .add_next_value('dist', {required=true}) @@ -78,10 +86,6 @@ local command = zeebo_argparse.from(arg) .add_next_value('url', {required=true}) .add_next_value('dist', {required=true}) -- - .add_subcommand('fs-gamefill', commands_fs) - .add_next_value('dist', {required=true}) - .add_next_value('size', {required=true}) - -- .add_subcommand('cli-build', commands_cli) .add_option_get('dist', {default='./dist/'}) .add_subcommand('cli-test', commands_cli) diff --git a/src/lib/cli/bundler.lua b/src/lib/cli/bundler.lua index d82bde8..d096e88 100644 --- a/src/lib/cli/bundler.lua +++ b/src/lib/cli/bundler.lua @@ -139,7 +139,7 @@ local function build(src_path, src_filename, dest) end until not line if from == 'lib' then - main_after = main_after..'end\n' + main_after = main_after..'end\n-'..'-\n' end end diff --git a/src/lib/cli/package.lua b/src/lib/cli/package.lua new file mode 100644 index 0000000..485309c --- /dev/null +++ b/src/lib/cli/package.lua @@ -0,0 +1,78 @@ +local function module_del(src_in, module_name) + local content = '' + local src_file, src_err = io.open(src_in, 'r') + + if not src_file then + return false, src_err + end + + local in_module = false + local module_name2 = '' + local module_name3 = '' + local pattern1 = 'local ([%w_]+) = nil' + local pattern2 = 'local ([%w_]+) = ([%w_]+)%(%)' + local pattern3 = ':package%(\'([%w@%.]+)\', ([%w_]+)' + local pattern4 = ':package%(\'([%w@%.]+)\', ([%w_]+), ([%w_]+)' + local pattern5 = '([%w_]+) = function' + + repeat + local line = src_file:read() + if line then + local skip_line = false + local module_p1 = {line:match(pattern1)} + local module_p2 = {line:match(pattern2)} + local module_p3 = {line:match(pattern3)} + local module_p4 = {line:match(pattern4)} + local module_34 = module_p4 and #module_p4 > 0 and module_p4 or module_p3 + local module_p5 = {line:match(pattern5)} + + if module_p1 and #module_p1 > 0 and module_p1[1] == module_name then + skip_line = true + end + if module_p2 and #module_p2 > 0 and module_p2[2] == module_name then + skip_line = true + module_name2 = module_p2[1] + end + if module_34 and #module_34 > 0 and module_34[2] then + if module_34[2] == module_name2 and module_34[3] then + skip_line = true + module_name3 = module_34[3] + end + if module_34[3] == module_name2 then + skip_line = true + end + end + if module_p5 and #module_p5 > 0 then + local module = module_p5[1] + if module == module_name or module == module_name2 or module == module_name3 then + in_module = true + end + end + + if in_module then + if line == '-'..'-' then + in_module = false + else + skip_line = true + end + end + + if not skip_line then + content = content..line..'\n' + end + end + until not line + + src_file:close() + src_file = io.open(src_in, 'wb') + src_file:write(content) + src_file:close() + + return true +end + +local P = { + del = module_del +} + +return P diff --git a/tools/ci_luau-analyze.lua b/tools/ci_luau-analyze.lua index fd8bdc3..4bac32b 100644 --- a/tools/ci_luau-analyze.lua +++ b/tools/ci_luau-analyze.lua @@ -3,3 +3,5 @@ local core = arg[1] or 'native' cmd('./cli.sh build --bundler --core '..core) cmd('./cli.sh fs-replace dist/main.lua dist/main.lua --format "function native_callback" --replace "local function _native_callback"') +cmd('./cli.sh tool-package-del dist/main.lua third_party_json_rxi') +cmd('./cli.sh tool-package-del dist/main.lua lib_engine_api_encoder') From 5e5b5f336b71126b8dc9b8adbf93ad67e59de4d0 Mon Sep 17 00:00:00 2001 From: RodrigoDornelles Date: Fri, 1 Nov 2024 17:22:22 -0300 Subject: [PATCH 4/5] feat: add wget protocoll #63 #90 --- src/lib/protocol/http_wget.lua | 37 ++++++++++++++++++++++++++++++++++ src/lib/util/http.lua | 7 +++++++ 2 files changed, 44 insertions(+) create mode 100644 src/lib/protocol/http_wget.lua diff --git a/src/lib/protocol/http_wget.lua b/src/lib/protocol/http_wget.lua new file mode 100644 index 0000000..b2479a4 --- /dev/null +++ b/src/lib/protocol/http_wget.lua @@ -0,0 +1,37 @@ +local http_util = require('src/lib/util/http') + +local function http_handler(self) + local params = http_util.url_search_param(self.param_list, self.param_dict) + local command, cleanup = http_util.create_request(self.method, self.url..params) + .add_custom_headers(self.header_list, self.header_dict) + .add_body_content(self.body_content) + .to_wget_cmd() + + local handle = io and io.popen and io.popen(command..'; echo $?') + + if handle then + local stdout = handle:read("*a") + local ok = handle:close() + local index = stdout:find("(%d+)\n$") + local ok2 = stdout:sub(index):find('0') + if not ok or not ok2 then + self.std.http.ok = false + self.std.http.error = 'unknown error!' + else + self.std.http.ok = 200 + self.std.http.body = stdout:sub(1, index - 2) + self.std.http.status = true + end + else + self.std.http.ok = false + self.std.http.error = 'failed to spawn process!' + end + + cleanup() +end + +local P = { + handler = http_handler +} + +return P diff --git a/src/lib/util/http.lua b/src/lib/util/http.lua index 2ca12ab..9662cc3 100644 --- a/src/lib/util/http.lua +++ b/src/lib/util/http.lua @@ -2,6 +2,12 @@ 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 @@ -183,6 +189,7 @@ end return { is_ok=is_ok, + is_ok_header=is_ok_header, is_redirect=is_redirect, url_search_param=url_search_param, create_request=create_request From b40c021c45eff900cde4689b41c1968faa721970 Mon Sep 17 00:00:00 2001 From: RodrigoDornelles Date: Fri, 1 Nov 2024 17:30:07 -0300 Subject: [PATCH 5/5] fix: bump doxygen 0.0.10 --- Doxyfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doxyfile b/Doxyfile index c42fc79..6d81574 100644 --- a/Doxyfile +++ b/Doxyfile @@ -1,7 +1,7 @@ # Custom Configs DOXYFILE_ENCODING = UTF-8 PROJECT_NAME = "Gly Game Engine" -PROJECT_NUMBER = 0.0.9 +PROJECT_NUMBER = 0.0.10 PROJECT_BRIEF = "Game engine in lua" PROJECT_LOGO = assets/icon80x80.png GENERATE_RTF = NO