colonelthirtytwo / luajit-glfw Goto Github PK
View Code? Open in Web Editor NEWOpenGL and GLFW bindings for LuaJIT. Not Maintained.
OpenGL and GLFW bindings for LuaJIT. Not Maintained.
d969f1a adds annotations to callback typedefs so that they may be marked as stdcall
under Windows. But the information needed to do this isn't available after preprocessing under Linux (since APIENTRY is defined as nothing).
I found that it would be good to have cdef.py in Lua.
I maked this one for me:
local function strip(cad)
return cad:gsub("^%s*(.-)%s*$","%1")
end
local defines = {}
local cdefs = {}
--location_re = '^# \d+ "([^"]*)"'
--glpath_re = '^(?:.*[\\/]|\A)(gl|glu|glfw3|glext)\.h$'
--define_re = "^#define\s+([^\s]+)\s+([^\s]+)$"
location_re = '^# %d+ "([^"]*)"'
glpath_re = '^(.*[\\/])(gl.-)%.h$' --'^(?:.*[\\/]|\A)(gl|glu|glfw3|glext)\.h$'
define_re = "^#define%s+([^%s]+)%s+([^%s]+)$"
number_re = "^-?[0-9]+$"
hex_re = "0x[0-9a-fA-F]+$"
-- 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}
local in_gl = false
for line in io.lines() do
repeat -- simulate continue with break
--print(line)
line = strip(line)
if #line == 0 then break end
-- Is this a preprocessor statement?
if line:sub(1,1) == "#" then
-- Is this a location pragma?
local location_match = line:match(location_re)
if location_match then
--print("location_match",line)
-- If we are transitioning to a header we need to parse, set the flag
local glpath_match,aaa = location_match:match(glpath_re)
in_gl = (glpath_match ~= nil)
--if in_gl then print(aaa) end
break
end
if in_gl then
local name,val = line:match(define_re)
if name then
--print("define ",name,val)
if defines[val] then
-- Is this an alias of something we have already defined?
val = defines[val]
elseif val:match(number_re) or val:match(hex_re) then
defines[name] = val
elseif val == "0xFFFFFFFFFFFFFFFFull" then
-- Fix for GL_TIMEOUT_IGNORED
defines[name] = val
elseif val == "0xFFFFFFFFu" then
-- Fix for GL_INVALID_INDEX
defines[name] = "0xFFFFFFFF"
elseif not INVALID_DEFINES[name] then
-- Incompatible define
print("xxxxxxxxxInvalid define:", name)
end
break
end
end
elseif in_gl then
-- Windows likes to add __stdcall__ to everything, but it isn't needed and is actually harmful when using under linux.
-- However, it is needed for callbacks in windows.
--if line:find("typedef") >= 0 and line.find(" PFNGL") < 0:
if line:find("typedef") and not line:find(" PFNGL") then
line = line:gsub("__attribute__%(%(__stdcall__%)%) ", 'WINDOWS_STDCALL ')
else
line = line:gsub("__attribute__%(%(__stdcall__%)%) ", '')
end
-- While linux likes to add __attribute__((visibility("default")))
line = line:gsub('__attribute__%(%(visibility%("default"%)%)%) ', '')
line = line:gsub("__attribute__%(%(__stdcall__%)%) ", '')
table.insert(cdefs,line)
end
until true
end
-- Output the file
print("--[[ BEGIN AUTOGENERATED SEGMENT ]]")
print("local glc; do local cdecl = [[")
for i,line in ipairs(cdefs) do
io.write("\t", line,"\n") --, sep="")
end
print("\t]]; if require('ffi').os == 'Windows' then cdecl = cdecl:gsub('WINDOWS_STDCALL', '__attribute__((__stdcall__))') else cdecl = cdecl:gsub('WINDOWS_STDCALL', '') end; require('ffi').cdef(cdecl); glc = {")
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]))
print(string.format("\t%s = %s,","['"..k.."']", defines[k]))
end
print("} end")
print("--[[ END AUTOGENERATED SEGMENT ]]")
victor bombi
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.