Skip to content

Commit

Permalink
Add dependencies on alphabetical order
Browse files Browse the repository at this point in the history
Also, headers are included first and later the modules.
  • Loading branch information
Andre-LA committed Apr 13, 2023
1 parent 3166669 commit 407a276
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 44 deletions.
19 changes: 17 additions & 2 deletions bindgen/generators/nelua.tl
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
65 changes: 39 additions & 26 deletions bindgen/utils.tl
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,52 @@ SPDX-License-Identifier: Zlib

local utils = {}

function utils.kpairs_to_alphabetic_ipairs<K,V>(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}): {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
2 changes: 1 addition & 1 deletion bindings/nelua/nene/collision.nelua
Original file line number Diff line number Diff line change
@@ -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 <cimport 'nene_Collision', nodecl> = @record{
Expand Down
4 changes: 2 additions & 2 deletions bindings/nelua/nene/core.nelua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
## cinclude '"nene/core.h"'

## cinclude '<SDL2/SDL.h>'
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'


Expand Down
6 changes: 3 additions & 3 deletions bindings/nelua/nene/font.nelua
Original file line number Diff line number Diff line change
@@ -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 '<SDL2/SDL_ttf.h>'
local Color = require 'nene.color'
local Texture = require 'nene.texture'
local Vec2i = require 'nene.math.vec2i'


require 'nene.raw.sdl2_ttf'
Expand Down
2 changes: 1 addition & 1 deletion bindings/nelua/nene/intersections.nelua
Original file line number Diff line number Diff line change
@@ -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{}
Expand Down
2 changes: 1 addition & 1 deletion bindings/nelua/nene/math/rect.nelua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## cinclude '"nene/math/rect.h"'

local Vec2i = require 'nene.math.vec2i'
## cinclude '<SDL2/SDL.h>'
local Vec2i = require 'nene.math.vec2i'


require 'nene.raw.sdl2'
Expand Down
2 changes: 1 addition & 1 deletion bindings/nelua/nene/math/shape.nelua
Original file line number Diff line number Diff line change
@@ -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{}
Expand Down
2 changes: 1 addition & 1 deletion bindings/nelua/nene/texture.nelua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## cinclude '"nene/texture.h"'

local Rect = require 'nene.math.rect'
## cinclude '<SDL2/SDL.h>'
local Color = require 'nene.color'
local Rect = require 'nene.math.rect'
local Vec2 = require 'nene.math.vec2'


Expand Down
2 changes: 1 addition & 1 deletion bindings/nelua/nene/texture_atlas.nelua
Original file line number Diff line number Diff line change
@@ -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'


Expand Down
2 changes: 1 addition & 1 deletion bindings/nelua/nene/tilemap.nelua
Original file line number Diff line number Diff line change
@@ -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'


Expand Down
8 changes: 4 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 407a276

Please sign in to comment.