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

Commit d969f1a

Browse files
Declare callback types with stdcall in Windows, fixing segfaults when trying to use them. (Not generated in non-windows builds, yet)
1 parent b36c6bb commit d969f1a

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

gen/cdef.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,21 @@
6262
# Otherwise just include it in the cdef
6363
elif in_gl:
6464
# Windows likes to add __stdcall__ to everything, but it isn't needed and is actually harmful when using under linux.
65-
line = line.replace('__attribute__((__stdcall__)) ', '')
65+
# However, it is needed for callbacks in windows.
66+
if line.find("typedef") >= 0 and line.find(" PFNGL") < 0:
67+
line = line.replace('__attribute__((__stdcall__)) ', 'WINDOWS_STDCALL ')
68+
else:
69+
line = line.replace('__attribute__((__stdcall__)) ', '')
6670
# While linux likes to add __attribute__((visibility("default")))
6771
line = line.replace('__attribute__((visibility("default"))) ', '')
6872
cdefs.append(line.replace('__attribute__((__stdcall__)) ', ''))
6973

7074
# Output the file
7175
print("--[[ BEGIN AUTOGENERATED SEGMENT ]]")
72-
print("local glc; do require('ffi').cdef [[")
76+
print("local glc; do local cdecl = [[")
7377
for line in cdefs:
7478
print("\t", line, sep="")
75-
print("\t]]; glc = {")
79+
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 = {")
7680

7781
for k in sorted(defines.keys()):
7882
print("\t%s = %s," % ("['"+k+"']", defines[k]))

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ Building
1010
--------
1111

1212
LuaJIT-GLFW builds bindings from the systems OpenGL and GLFW headers, as well as an included `glext.h` file.
13-
To build the bindings, you need to have `gcc`, headers for OpenGL and GLFW 3, and Python 3 installed, though the resulting
13+
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
1414
file should be cross-platform compatible.
1515

16-
To build, just run `build.sh` in the repository directory. This will create a `glfw.lua` file, which is the only file
16+
To build with GCC, just run `build.sh` in the repository directory. This will create a `glfw.lua` file, which is the only file
1717
you need to install.
1818

1919
Usage

0 commit comments

Comments
 (0)