Skip to content
This repository was archived by the owner on Jul 1, 2020. It is now read-only.

automate with lua and add glfw as submodule #5

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ccfc1bc
allowing lua generator
sonoro1234 Dec 21, 2016
f015737
add GLFW as submodule, include from build.bat and add invalid defines…
sonoro1234 Dec 21, 2016
7a311c3
update readme.md
sonoro1234 Dec 21, 2016
35f986f
provide generated glfw.lua (in case you dont want to generate)
sonoro1234 Dec 21, 2016
80fcbb6
attribs can be zero
sonoro1234 Dec 23, 2016
8938773
glfwGetWindowAttrib can return 0, window creation without name
sonoro1234 Feb 4, 2017
51e5ab8
update GLFW submodule
sonoro1234 Feb 26, 2018
589a43e
update GLFW submodule
sonoro1234 Jun 5, 2018
0920285
update GLFW
sonoro1234 Oct 28, 2018
7afe77d
generate separated glfw.lua and gl.lua
sonoro1234 Nov 12, 2018
2fd50e5
add gl.lua and modify test.lua
sonoro1234 Nov 12, 2018
7eac1f8
update readme
sonoro1234 Nov 12, 2018
690d7f8
add set_loader method
sonoro1234 Nov 13, 2018
170c88c
better loader detection
sonoro1234 Nov 19, 2018
8230583
update readme.md
sonoro1234 Nov 19, 2018
c228047
regenerate gl.lua
sonoro1234 Nov 23, 2018
78d0acb
add CMake
sonoro1234 Nov 26, 2018
910cdb8
correct test.lua
sonoro1234 Nov 28, 2018
cda8b5e
better submodule management
sonoro1234 Dec 17, 2018
09c8d88
cmake installs GLFW for findpackage
sonoro1234 Feb 22, 2019
bf1cd89
cmake for add_subdirectory
sonoro1234 Feb 26, 2019
0b99828
cmake:library destination for linux
sonoro1234 Apr 24, 2019
fe4916a
gl loading in linux
sonoro1234 Apr 28, 2019
801bdba
gl: add glErrorWrap for getting errors after each gl or glext function
sonoro1234 Oct 11, 2019
58d9086
pull GLFW 3.3 and regenerate
sonoro1234 Dec 8, 2019
ea7793b
pull GLFW and generate
sonoro1234 May 27, 2020
bf84bfe
pull GLFW 3.3.2+ and generate
sonoro1234 Feb 8, 2021
38d14e8
opengl 4_6 generation
sonoro1234 Mar 23, 2022
509c565
remove GL (now in LuaJIT-GL repo)
sonoro1234 Nov 26, 2022
ed4b2b6
pull GLFW 3.3.8 and generate
sonoro1234 Nov 26, 2022
bcb677f
pull GLFW 3.3.9 and generate
sonoro1234 Dec 26, 2023
4deba2e
pull glfw 3.4 and generate
sonoro1234 May 26, 2024
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
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__pycache__
glfw.lua

3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "GLFW"]
path = GLFW
url = https://github.com/glfw/glfw.git
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
PROJECT(glfw_ffi)
#to allow install from subdirectory
cmake_minimum_required(VERSION 3.13)

set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE)
#set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install)
add_subdirectory(GLFW EXCLUDE_FROM_ALL)
add_custom_target(glfw_ffi ALL)
add_dependencies(glfw_ffi glfw)


install(TARGETS glfw RUNTIME DESTINATION ${LUAJIT_BIN}
LIBRARY DESTINATION ${LUAJIT_BIN}
)
INSTALL(FILES glfw.lua DESTINATION ${LUAJIT_BIN}/lua)
1 change: 1 addition & 0 deletions GLFW
Submodule GLFW added at 7b6aea
3 changes: 0 additions & 3 deletions build.sh

This file was deleted.

1 change: 0 additions & 1 deletion gen/.gitignore

This file was deleted.

7 changes: 7 additions & 0 deletions gen/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rem set your PATH if necessary for gcc and lua with:
set PATH=%PATH%;C:\mingws\i686-7.2.0-release-posix-dwarf-rt_v5-rev1\mingw32\bin;C:\anima;
::set PATH=%PATH%;C:\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\mingw64\bin;C:\luaGL;
luajit.exe ./generator.lua

cmd /k

85 changes: 0 additions & 85 deletions gen/cdef.py

This file was deleted.

152 changes: 152 additions & 0 deletions gen/generator.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@

local function strip(cad)
return cad:gsub("^%s*(.-)%s*$","%1") --remove initial and final spaces
end

local function save_data(filename,...)
local file = io.open(filename,"w")
for i=1, select('#', ...) do
local data = select(i, ...)
file:write(data)
end
file:close()
end


-- Set of known #defines that we don't need to include
INVALID_DEFINES = {GLAPI=1, APIENTRY=1, GLU_TESS_MAX_COORD=1, gluErrorStringWIN=1, WINGDIAPI=1, CALLBACK=1, GLAPIENTRY=1}

--iterates lines from a gcc/clang -E in a specific location
local function location(file,locpathT,defines)
local define_re = "^#define%s+([^%s]+)%s+([^%s]+)$"
local number_re = "^-?[0-9]+$"
local hex_re = "0x[0-9a-fA-F]+$"
local location_re
if COMPILER == "cl" then
location_re = '^#line (%d+) "([^"]*)"'
else --gcc, clang
location_re = '^# (%d+) "([^"]*)"'
end
local path_reT = {}
for i,locpath in ipairs(locpathT) do
table.insert(path_reT,'^(.*[\\/])('..locpath..')%.h$')
end
local in_location = false
local which_location = ""
local loc_num
local loc_num_incr
local lineold = ""
local which_locationold,loc_num_realold
local lastdumped = false
local function location_it()
repeat
local line = file:read"*l"
if not line then
if not lastdumped then
lastdumped = true
return lineold, which_locationold,loc_num_realold
else
return nil
end
end
if #line==0 then --nothing on emptyline
elseif not line:match("%S") then --nothing if only spaces
elseif line:sub(1,1) == "#" then
-- Is this a location pragma?
local loc_num_t,location_match = line:match(location_re)
if location_match then
in_location = false
for i,path_re in ipairs(path_reT) do
if location_match:match(path_re) then
in_location = true;
loc_num = loc_num_t
loc_num_incr = 0
which_location = locpathT[i]
break
end
end
elseif in_location then
local name,val = line:match(define_re)
if name then
while defines[val] do val = defines[val] end
if val:match(number_re) or val:match(hex_re) then
defines[name] = val
end
end
end

elseif in_location then
local loc_num_real = loc_num + loc_num_incr
loc_num_incr = loc_num_incr + 1
if loc_num_realold and loc_num_realold < loc_num_real then
--old line complete
local lineR,which_locationR,loc_num_realR = lineold, which_locationold,loc_num_realold
lineold, which_locationold,loc_num_realold = line,which_location,loc_num_real
return lineR,which_locationR,loc_num_realR
else
lineold=lineold..line
which_locationold,loc_num_realold = which_location,loc_num_real
--return line,loc_num_real, which_location
end
end
until false --forever
end
return location_it
end

local function define_str(name,defines)
local tab = {"local "..name.."= {"}
local defines_keys = {}
for k,v in pairs(defines) do
table.insert(defines_keys,k)
end
table.sort(defines_keys)
for i,k in ipairs(defines_keys) do
--print("\t%s = %s," % ("['"..k.."']", defines[k]))
table.insert(tab,string.format("\t%s = %s,","['"..k.."']", defines[k]))
end
table.insert(tab,"}")
return table.concat(tab,"\n")
end
local function copyfile(src,dst,blocksize)
blocksize = blocksize or 1024*4
print( "copyfile", src, dst)
local srcf, err = io.open(src,"rb")
if not srcf then error(err) end
local dstf, err = io.open(dst,"wb")
if not dstf then error(err) end
while true do
local data = srcf:read(blocksize)
if not data then break end
dstf:write(data)
end
srcf:close()
dstf:close()
end
------------------------------------------------------
local cdefs = {}

save_data("./outheader.h",[[#include <GLFW/glfw3.h>]])
local pipe,err = io.popen([[gcc -E -dD -I ../GLFW/include/ ./outheader.h]],"r")
if not pipe then
error("could not execute gcc "..err)
end

local defines = {}
for line in location(pipe,{"glfw.-"},defines) do
local line = strip(line)
table.insert(cdefs,line)
end
pipe:close()
os.remove"./outheader.h"
--save
local glfwstr = "local cdecl=[[\n"..table.concat(cdefs,"\n").."]]\n"
glfwstr = glfwstr..define_str("glfwc",defines)
local hfile = io.open("./glfw_base.lua","r")
local hstrfile = hfile:read"*a"
hfile:close()
save_data("./glfw.lua",glfwstr,hstrfile)



copyfile("./glfw.lua","../glfw.lua")
Loading