Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix: 0.0.10 #112

Merged
merged 5 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
strategy:
fail-fast: false
matrix:
core: ['native']
core: ['native', 'love']
steps:
-
uses: actions/checkout@master
Expand Down
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion src/cli/commands/tools.lua
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
8 changes: 8 additions & 0 deletions src/cli/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
2 changes: 1 addition & 1 deletion src/lib/cli/bundler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
31 changes: 31 additions & 0 deletions src/lib/cli/filler.lua
Original file line number Diff line number Diff line change
@@ -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
78 changes: 78 additions & 0 deletions src/lib/cli/package.lua
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions src/lib/protocol/http_wget.lua
Original file line number Diff line number Diff line change
@@ -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
68 changes: 21 additions & 47 deletions src/lib/util/http.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -128,86 +134,53 @@ local function create_request(method, uri)
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, ' ')

return request, function() end
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)
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)

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

Expand All @@ -216,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
Expand Down
2 changes: 2 additions & 0 deletions tools/ci_luau-analyze.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Loading