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

Commit

Permalink
Declare callback types with stdcall in Windows, fixing segfaults when…
Browse files Browse the repository at this point in the history
… trying to use them. (Not generated in non-windows builds, yet)
  • Loading branch information
ColonelThirtyTwo committed Feb 15, 2014
1 parent b36c6bb commit d969f1a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions gen/cdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d969f1a

Please sign in to comment.