From 407a276d77bb19c7fed9d45f03f9b5c7231ad4b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Luiz=20Alvares?= Date: Thu, 13 Apr 2023 14:14:47 -0300 Subject: [PATCH] Add dependencies on alphabetical order Also, headers are included first and later the modules. --- bindgen/generators/nelua.tl | 19 +++++++- bindgen/utils.tl | 65 +++++++++++++++---------- bindings/nelua/nene/collision.nelua | 2 +- bindings/nelua/nene/core.nelua | 4 +- bindings/nelua/nene/font.nelua | 6 +-- bindings/nelua/nene/intersections.nelua | 2 +- bindings/nelua/nene/math/rect.nelua | 2 +- bindings/nelua/nene/math/shape.nelua | 2 +- bindings/nelua/nene/texture.nelua | 2 +- bindings/nelua/nene/texture_atlas.nelua | 2 +- bindings/nelua/nene/tilemap.nelua | 2 +- build.sh | 8 +-- 12 files changed, 72 insertions(+), 44 deletions(-) diff --git a/bindgen/generators/nelua.tl b/bindgen/generators/nelua.tl index b121d4f..9368c8a 100644 --- a/bindgen/generators/nelua.tl +++ b/bindgen/generators/nelua.tl @@ -5,6 +5,7 @@ Please refer to the LICENSE file for details SPDX-License-Identifier: Zlib ]] +local utils = require 'bindgen.utils' local Node = require 'bindgen.node' local Generator = require 'bindgen.generator' local Dependencies = require 'bindgen.dependencies' @@ -114,8 +115,22 @@ function NeluaGenerator:dependencies(dependencies: Dependencies, wrap_options: G end -- generate required modules or headers - for dep_name, dep in pairs(dependencies.dependencies) do - table.insert(result, self:dependency(dep_name, dep, wrap_options)) + local dep_names, _ = utils.kpairs_to_alphabetic_ipairs(dependencies.dependencies) + + -- generate required headers + for _, dep_name in ipairs(dep_names) do + local dep = dependencies.dependencies[dep_name] + if dep.is_header then + table.insert(result, self:dependency(dep_name, dep, wrap_options)) + end + end + + -- generate required modules + for _, dep_name in ipairs(dep_names) do + local dep = dependencies.dependencies[dep_name] + if not dep.is_header then + table.insert(result, self:dependency(dep_name, dep, wrap_options)) + end end return table.concat(result, '\n') .. '\n' diff --git a/bindgen/utils.tl b/bindgen/utils.tl index 404762f..021aee5 100644 --- a/bindgen/utils.tl +++ b/bindgen/utils.tl @@ -7,39 +7,52 @@ SPDX-License-Identifier: Zlib local utils = {} +function utils.kpairs_to_alphabetic_ipairs(tbl: {K:V}): ({K}, {V}) + local keys: {K} = {} + local values: {V} = {} + for k, _ in pairs(tbl) do + table.insert(keys, k) + end + table.sort(keys) + for i, k in ipairs(keys) do + values[i] = tbl[k] + end + return keys, values +end + function utils.imerge(...: {T}): {T} - local result: {T} = {} - for i = 1, select('#', ...) do - local t = select(i, ...) - for j = 1, #t do - table.insert(result, t[j]) - end - end - return result + local result: {T} = {} + for i = 1, select('#', ...) do + local t = select(i, ...) + for j = 1, #t do + table.insert(result, t[j]) + end + end + return result end function utils.no_repeat(values: {any}, predicate: function(any): any): {any} - local result: {any} = {} - local tbl: {any:boolean} = {} - - for _, value in ipairs(values) do - local r: any = predicate(value) - if not tbl[r] then - table.insert(result, value) - tbl[r] = true - end - end - - return result + local result: {any} = {} + local tbl: {any:boolean} = {} + + for _, value in ipairs(values) do + local r: any = predicate(value) + if not tbl[r] then + table.insert(result, value) + tbl[r] = true + end + end + + return result end function utils.ifindk(tbl: {any}, value: any, searcher: function(v: any): any): any - for _, v in ipairs(tbl) do - if searcher(v) == value then - return v - end - end - return nil + for _, v in ipairs(tbl) do + if searcher(v) == value then + return v + end + end + return nil end return utils diff --git a/bindings/nelua/nene/collision.nelua b/bindings/nelua/nene/collision.nelua index 286e663..315e2e4 100644 --- a/bindings/nelua/nene/collision.nelua +++ b/bindings/nelua/nene/collision.nelua @@ -1,8 +1,8 @@ ## cinclude '"nene/collision.h"' +local Rectf = require 'nene.math.rectf' local Segment = require 'nene.math.segment' local Vec2 = require 'nene.math.vec2' -local Rectf = require 'nene.math.rectf' -- Collision data structure. local Collision = @record{ diff --git a/bindings/nelua/nene/core.nelua b/bindings/nelua/nene/core.nelua index d552399..229c7df 100644 --- a/bindings/nelua/nene/core.nelua +++ b/bindings/nelua/nene/core.nelua @@ -1,9 +1,9 @@ ## cinclude '"nene/core.h"' ## cinclude '' -local Vec2 = require 'nene.math.vec2' -local Rect = require 'nene.math.rect' local Color = require 'nene.color' +local Rect = require 'nene.math.rect' +local Vec2 = require 'nene.math.vec2' local Vec2i = require 'nene.math.vec2i' diff --git a/bindings/nelua/nene/font.nelua b/bindings/nelua/nene/font.nelua index de36c13..89bfacb 100644 --- a/bindings/nelua/nene/font.nelua +++ b/bindings/nelua/nene/font.nelua @@ -1,9 +1,9 @@ ## cinclude '"nene/font.h"' -local Vec2i = require 'nene.math.vec2i' -local Texture = require 'nene.texture' -local Color = require 'nene.color' ## cinclude '' +local Color = require 'nene.color' +local Texture = require 'nene.texture' +local Vec2i = require 'nene.math.vec2i' require 'nene.raw.sdl2_ttf' diff --git a/bindings/nelua/nene/intersections.nelua b/bindings/nelua/nene/intersections.nelua index 99ede01..50e909c 100644 --- a/bindings/nelua/nene/intersections.nelua +++ b/bindings/nelua/nene/intersections.nelua @@ -1,8 +1,8 @@ ## cinclude '"nene/intersections.h"' +local Rectf = require 'nene.math.rectf' local Segment = require 'nene.math.segment' local Vec2 = require 'nene.math.vec2' -local Rectf = require 'nene.math.rectf' local Intersections = @record{} diff --git a/bindings/nelua/nene/math/rect.nelua b/bindings/nelua/nene/math/rect.nelua index bb4a911..15d5a9f 100644 --- a/bindings/nelua/nene/math/rect.nelua +++ b/bindings/nelua/nene/math/rect.nelua @@ -1,7 +1,7 @@ ## cinclude '"nene/math/rect.h"' -local Vec2i = require 'nene.math.vec2i' ## cinclude '' +local Vec2i = require 'nene.math.vec2i' require 'nene.raw.sdl2' diff --git a/bindings/nelua/nene/math/shape.nelua b/bindings/nelua/nene/math/shape.nelua index d789896..b7409c2 100644 --- a/bindings/nelua/nene/math/shape.nelua +++ b/bindings/nelua/nene/math/shape.nelua @@ -1,8 +1,8 @@ ## cinclude '"nene/math/segment.h"' -local Segment = require 'nene.math.segment' local Rect = require 'nene.math.rect' local Rectf = require 'nene.math.rectf' +local Segment = require 'nene.math.segment' local Shape = @record{} diff --git a/bindings/nelua/nene/texture.nelua b/bindings/nelua/nene/texture.nelua index cdbd9f9..485f696 100644 --- a/bindings/nelua/nene/texture.nelua +++ b/bindings/nelua/nene/texture.nelua @@ -1,8 +1,8 @@ ## cinclude '"nene/texture.h"' -local Rect = require 'nene.math.rect' ## cinclude '' local Color = require 'nene.color' +local Rect = require 'nene.math.rect' local Vec2 = require 'nene.math.vec2' diff --git a/bindings/nelua/nene/texture_atlas.nelua b/bindings/nelua/nene/texture_atlas.nelua index 5c3b49e..1a2d04a 100644 --- a/bindings/nelua/nene/texture_atlas.nelua +++ b/bindings/nelua/nene/texture_atlas.nelua @@ -1,8 +1,8 @@ ## cinclude '"nene/texture_atlas.h"' local Grid = require 'nene.math.grid' -local Vec2 = require 'nene.math.vec2' local Texture = require 'nene.texture' +local Vec2 = require 'nene.math.vec2' local Vec2i = require 'nene.math.vec2i' diff --git a/bindings/nelua/nene/tilemap.nelua b/bindings/nelua/nene/tilemap.nelua index 9a27f72..b208397 100644 --- a/bindings/nelua/nene/tilemap.nelua +++ b/bindings/nelua/nene/tilemap.nelua @@ -1,8 +1,8 @@ ## cinclude '"nene/tilemap.h"' local Grid = require 'nene.math.grid' -local Vec2 = require 'nene.math.vec2' local TextureAtlas = require 'nene.texture_atlas' +local Vec2 = require 'nene.math.vec2' local Vec2i = require 'nene.math.vec2i' diff --git a/build.sh b/build.sh index bc17b05..cd04c44 100644 --- a/build.sh +++ b/build.sh @@ -13,7 +13,7 @@ # you can also change the C compiler or object archiver by # passing arguments, like: "$ sh build.sh emcc emar" # -# note: currently only clang with llvm-ar, and emcc with emar are tested. +# Note: currently only clang with llvm-ar, and emcc with emar are tested. # utils build_log() { @@ -43,13 +43,13 @@ build_log "Object achiver: $AR" ## warning flags WFLAGS="-Wall -Wextra -Wpedantic" -# C standard flag +## C standard flag CSTD="-std=c99" -# include flags +## include flags IFLAGS="-I./include/" -# source files +## source files SOURCES="src/*.c src/math/*.c src/audio/*.c" # clear previous build