Skip to content

Commit

Permalink
feat: add support to haxe language #86
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoDornelles committed Oct 4, 2024
1 parent 540bdcc commit de6baf8
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 15 deletions.
27 changes: 27 additions & 0 deletions src/cli/commands/haxe.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
local function build(args)
local game_name = args.game
local game_file = io.open(game_name, 'r')
local game_content = game_file and game_file:read('*a')

if not game_content then
return false, 'game not found!'
end

local pattern_utf8 = '_G%.require%("lua%-utf8"%)'
local replace_utf8 = 'select(2, pcall(require, "lua-utf8")) or select(2, pcall(require, "utf8")) or string'
local pattern_object = 'std%.(%w+):(%w+)'
local replace_object = 'std.%1.%2'

game_content = game_content:gsub(pattern_utf8, replace_utf8)
game_content = game_content:gsub(pattern_object, replace_object)

game_file = io.open(game_name, 'w')
game_file:write(game_content)
return true
end

local P = {
['tool-haxe-build'] = build
}

return P
4 changes: 4 additions & 0 deletions src/cli/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local commands_build = require('src/cli/commands/build')
local commands_cli = require('src/cli/commands/cli')
local commands_fs = require('src/cli/commands/fs')
local commands_game = require('src/cli/commands/game')
local commands_haxe = require('src/cli/commands/haxe')
local commands_info = require('src/cli/commands/info')
local commands_tools = require('src/cli/commands/tools')

Expand Down Expand Up @@ -42,6 +43,9 @@ local command = zeebo_argparse.from(arg)
.add_next_value('file', {required=true})
.add_option_get('dist', {default='a.out'})
--
.add_subcommand('tool-haxe-build', commands_haxe)
.add_next_value('game', {required=true})
--
.add_subcommand('tool-love-zip', commands_tools)
.add_next_value('path', {required=true})
.add_option_get('dist', {required=true})
Expand Down
15 changes: 3 additions & 12 deletions src/lib/cli/meta.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local application_default = require('src/lib/object/application')
local zeebo_module = require('src/lib/engine/module')

local function replace(src, meta, default)
if src and #src > 0 then
Expand Down Expand Up @@ -65,18 +66,8 @@ local function run(self)
return self
end

local function current(game, application)
local gamefile = game and io.open(game, 'r')
local bytecode = gamefile and gamefile:read('*a')
local metadata = bytecode and (loadstring and loadstring(bytecode) or load(bytecode))

if gamefile then
gamefile:close()
end

while type(metadata) == 'function' do
metadata = metadata()
end
local function current(gamefile, application)
local metadata = zeebo_module.loadgame(gamefile)

if not application then
application = {
Expand Down
45 changes: 42 additions & 3 deletions src/lib/engine/module.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,52 @@
local zeebo_pipeline = require('src/lib/util/pipeline')
local application_default = require('src/lib/object/application')

local function normalize(application)
if not application then return nil end

if application.Game then
application = application.Game
end

if application.new and type(application.new) == 'function' then
application = application.new()
end

if application and application.meta and application.callbacks then
return application
end

local normalized_aplication = {
meta = {},
config = {},
callbacks = {}
}

for key, value in pairs(application) do
if application_default.meta[key] then
normalized_aplication.meta[key] = value
elseif type(value) == 'function' then
normalized_aplication.callbacks[key] = value
else
normalized_aplication.config[key] = value
end
end

return normalized_aplication
end

--! @short safe load game
--! @brief search by game in filesystem / lua modules
--! @li https://love2d.org/wiki/love.filesystem.getSource
local function loadgame(game_file)
if type(game_file) == 'table' then
return game_file
return normalize(game_file)
end


if not game_file then
return nil
end

local cwd = '.'
local application = type(game_file) == 'function' and game_file
local game_title = game_file and game_file:gsub('%.lua$', '') or 'game'
Expand Down Expand Up @@ -48,7 +87,7 @@ local function loadgame(game_file)
application = application()
end

return application
return normalize(application)
end

local function register(self, register_func)
Expand Down

0 comments on commit de6baf8

Please sign in to comment.