From d969f1aa0b0a7e7496f3bbcd4a8cd627520ab54d Mon Sep 17 00:00:00 2001 From: Alex Parrill Date: Sat, 15 Feb 2014 10:52:39 -0500 Subject: [PATCH] Declare callback types with stdcall in Windows, fixing segfaults when trying to use them. (Not generated in non-windows builds, yet) --- gen/cdef.py | 10 +++++++--- readme.md | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/gen/cdef.py b/gen/cdef.py index 1d8b381..d1c2191 100644 --- a/gen/cdef.py +++ b/gen/cdef.py @@ -62,17 +62,21 @@ # Otherwise just include it in the cdef elif in_gl: # Windows likes to add __stdcall__ to everything, but it isn't needed and is actually harmful when using under linux. - line = line.replace('__attribute__((__stdcall__)) ', '') + # However, it is needed for callbacks in windows. + if line.find("typedef") >= 0 and line.find(" PFNGL") < 0: + line = line.replace('__attribute__((__stdcall__)) ', 'WINDOWS_STDCALL ') + else: + line = line.replace('__attribute__((__stdcall__)) ', '') # While linux likes to add __attribute__((visibility("default"))) line = line.replace('__attribute__((visibility("default"))) ', '') cdefs.append(line.replace('__attribute__((__stdcall__)) ', '')) # Output the file print("--[[ BEGIN AUTOGENERATED SEGMENT ]]") - print("local glc; do require('ffi').cdef [[") + print("local glc; do local cdecl = [[") for line in cdefs: print("\t", line, sep="") - print("\t]]; glc = {") + 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 = {") for k in sorted(defines.keys()): print("\t%s = %s," % ("['"+k+"']", defines[k])) diff --git a/readme.md b/readme.md index 939666d..845ba2d 100644 --- a/readme.md +++ b/readme.md @@ -10,10 +10,10 @@ Building -------- LuaJIT-GLFW builds bindings from the systems OpenGL and GLFW headers, as well as an included `glext.h` file. -To build the bindings, you need to have `gcc`, headers for OpenGL and GLFW 3, and Python 3 installed, though the resulting +To build the bindings, you need to have a C preprocessor (only GCC is supported at the moment), headers for OpenGL and GLFW 3, and Python 3 installed, though the resulting file should be cross-platform compatible. -To build, just run `build.sh` in the repository directory. This will create a `glfw.lua` file, which is the only file +To build with GCC, just run `build.sh` in the repository directory. This will create a `glfw.lua` file, which is the only file you need to install. Usage