ruby-glfw 0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. data/README +1 -0
  2. data/README.API +73 -0
  3. data/Rakefile +120 -0
  4. data/examples/boing.rb +519 -0
  5. data/examples/gears.rb +327 -0
  6. data/examples/keytest.rb +117 -0
  7. data/examples/listmodes.rb +20 -0
  8. data/examples/mipmaps.rb +104 -0
  9. data/examples/mipmaps.tga +0 -0
  10. data/examples/particles.rb +837 -0
  11. data/examples/pong3d.rb +741 -0
  12. data/examples/pong3d_field.tga +0 -0
  13. data/examples/pong3d_instr.tga +0 -0
  14. data/examples/pong3d_menu.tga +0 -0
  15. data/examples/pong3d_title.tga +0 -0
  16. data/examples/pong3d_winner1.tga +0 -0
  17. data/examples/pong3d_winner2.tga +0 -0
  18. data/examples/splitview.rb +432 -0
  19. data/examples/triangle.rb +89 -0
  20. data/examples/wave.rb +294 -0
  21. data/ext/glfw/glfw.c +1094 -0
  22. data/ext/glfw/mkrf_conf.rb +70 -0
  23. data/glfw-src/Makefile +220 -0
  24. data/glfw-src/compile.ami +61 -0
  25. data/glfw-src/compile.bat +217 -0
  26. data/glfw-src/compile.sh +607 -0
  27. data/glfw-src/docs/Makefile +57 -0
  28. data/glfw-src/docs/Reference.pdf +0 -0
  29. data/glfw-src/docs/UsersGuide.pdf +0 -0
  30. data/glfw-src/docs/cleanup.bat +22 -0
  31. data/glfw-src/docs/glfwdoc.sty +80 -0
  32. data/glfw-src/docs/glfwrm.tex +3034 -0
  33. data/glfw-src/docs/glfwug.tex +2024 -0
  34. data/glfw-src/docs/readme.txt +80 -0
  35. data/glfw-src/examples/Makefile.amigaos.gcc +70 -0
  36. data/glfw-src/examples/Makefile.amigaos.vbcc +70 -0
  37. data/glfw-src/examples/Makefile.dos.djgpp +71 -0
  38. data/glfw-src/examples/Makefile.macosx.gcc +96 -0
  39. data/glfw-src/examples/Makefile.win32.bcc +75 -0
  40. data/glfw-src/examples/Makefile.win32.cross-mgw +79 -0
  41. data/glfw-src/examples/Makefile.win32.cygwin +79 -0
  42. data/glfw-src/examples/Makefile.win32.lcc +74 -0
  43. data/glfw-src/examples/Makefile.win32.mgw +75 -0
  44. data/glfw-src/examples/Makefile.win32.msvc +74 -0
  45. data/glfw-src/examples/Makefile.win32.ow +74 -0
  46. data/glfw-src/examples/Makefile.win32.pellesc +74 -0
  47. data/glfw-src/examples/Makefile.x11.in +54 -0
  48. data/glfw-src/examples/boing.c +606 -0
  49. data/glfw-src/examples/bundle.sh +46 -0
  50. data/glfw-src/examples/gears.c +382 -0
  51. data/glfw-src/examples/keytest.c +264 -0
  52. data/glfw-src/examples/listmodes.c +48 -0
  53. data/glfw-src/examples/mipmaps.c +126 -0
  54. data/glfw-src/examples/mipmaps.tga +0 -0
  55. data/glfw-src/examples/mtbench.c +301 -0
  56. data/glfw-src/examples/mthello.c +48 -0
  57. data/glfw-src/examples/particles.c +1148 -0
  58. data/glfw-src/examples/pong3d.c +839 -0
  59. data/glfw-src/examples/pong3d_field.tga +0 -0
  60. data/glfw-src/examples/pong3d_instr.tga +0 -0
  61. data/glfw-src/examples/pong3d_menu.tga +0 -0
  62. data/glfw-src/examples/pong3d_title.tga +0 -0
  63. data/glfw-src/examples/pong3d_winner1.tga +0 -0
  64. data/glfw-src/examples/pong3d_winner2.tga +0 -0
  65. data/glfw-src/examples/splitview.c +506 -0
  66. data/glfw-src/examples/triangle.c +108 -0
  67. data/glfw-src/examples/wave.c +397 -0
  68. data/glfw-src/images/opengl.gif +0 -0
  69. data/glfw-src/images/osicert.gif +0 -0
  70. data/glfw-src/include/GL/glfw.h +486 -0
  71. data/glfw-src/lib/amigaos/Makefile.amigaos.gcc +128 -0
  72. data/glfw-src/lib/amigaos/Makefile.amigaos.vbcc +128 -0
  73. data/glfw-src/lib/amigaos/SDI_compiler.h +94 -0
  74. data/glfw-src/lib/amigaos/amigaos_enable.c +51 -0
  75. data/glfw-src/lib/amigaos/amigaos_fullscreen.c +319 -0
  76. data/glfw-src/lib/amigaos/amigaos_glext.c +61 -0
  77. data/glfw-src/lib/amigaos/amigaos_init.c +284 -0
  78. data/glfw-src/lib/amigaos/amigaos_joystick.c +359 -0
  79. data/glfw-src/lib/amigaos/amigaos_thread.c +494 -0
  80. data/glfw-src/lib/amigaos/amigaos_time.c +206 -0
  81. data/glfw-src/lib/amigaos/amigaos_window.c +830 -0
  82. data/glfw-src/lib/amigaos/platform.h +337 -0
  83. data/glfw-src/lib/dos/Makefile.dos.djgpp +146 -0
  84. data/glfw-src/lib/dos/dos_enable.c +51 -0
  85. data/glfw-src/lib/dos/dos_events.c +173 -0
  86. data/glfw-src/lib/dos/dos_fullscreen.c +101 -0
  87. data/glfw-src/lib/dos/dos_glext.c +59 -0
  88. data/glfw-src/lib/dos/dos_init.c +105 -0
  89. data/glfw-src/lib/dos/dos_irq.s +246 -0
  90. data/glfw-src/lib/dos/dos_joystick.c +94 -0
  91. data/glfw-src/lib/dos/dos_keyboard.c +694 -0
  92. data/glfw-src/lib/dos/dos_mouse.c +337 -0
  93. data/glfw-src/lib/dos/dos_thread.c +267 -0
  94. data/glfw-src/lib/dos/dos_time.c +309 -0
  95. data/glfw-src/lib/dos/dos_window.c +563 -0
  96. data/glfw-src/lib/dos/platform.h +341 -0
  97. data/glfw-src/lib/enable.c +295 -0
  98. data/glfw-src/lib/fullscreen.c +95 -0
  99. data/glfw-src/lib/glext.c +201 -0
  100. data/glfw-src/lib/image.c +629 -0
  101. data/glfw-src/lib/init.c +108 -0
  102. data/glfw-src/lib/input.c +280 -0
  103. data/glfw-src/lib/internal.h +210 -0
  104. data/glfw-src/lib/joystick.c +101 -0
  105. data/glfw-src/lib/macosx/Makefile.macosx.gcc +172 -0
  106. data/glfw-src/lib/macosx/Makefile.macosx.gcc.universal +166 -0
  107. data/glfw-src/lib/macosx/libglfw.pc.in +11 -0
  108. data/glfw-src/lib/macosx/macosx_enable.c +42 -0
  109. data/glfw-src/lib/macosx/macosx_fullscreen.c +126 -0
  110. data/glfw-src/lib/macosx/macosx_glext.c +52 -0
  111. data/glfw-src/lib/macosx/macosx_init.c +194 -0
  112. data/glfw-src/lib/macosx/macosx_joystick.c +50 -0
  113. data/glfw-src/lib/macosx/macosx_thread.c +414 -0
  114. data/glfw-src/lib/macosx/macosx_time.c +112 -0
  115. data/glfw-src/lib/macosx/macosx_window.c +1279 -0
  116. data/glfw-src/lib/macosx/platform.h +349 -0
  117. data/glfw-src/lib/stream.c +194 -0
  118. data/glfw-src/lib/tga.c +405 -0
  119. data/glfw-src/lib/thread.c +340 -0
  120. data/glfw-src/lib/time.c +83 -0
  121. data/glfw-src/lib/win32/Makefile.win32.bcc +265 -0
  122. data/glfw-src/lib/win32/Makefile.win32.cross-mgw +274 -0
  123. data/glfw-src/lib/win32/Makefile.win32.cygwin +279 -0
  124. data/glfw-src/lib/win32/Makefile.win32.lcc +246 -0
  125. data/glfw-src/lib/win32/Makefile.win32.mgw +243 -0
  126. data/glfw-src/lib/win32/Makefile.win32.msvc +242 -0
  127. data/glfw-src/lib/win32/Makefile.win32.ow +242 -0
  128. data/glfw-src/lib/win32/Makefile.win32.pellesc +242 -0
  129. data/glfw-src/lib/win32/glfwdll.def +67 -0
  130. data/glfw-src/lib/win32/glfwdll_mgw1.def +67 -0
  131. data/glfw-src/lib/win32/glfwdll_mgw2.def +67 -0
  132. data/glfw-src/lib/win32/glfwdll_pellesc.def +65 -0
  133. data/glfw-src/lib/win32/libglfw.pc.in +11 -0
  134. data/glfw-src/lib/win32/platform.h +474 -0
  135. data/glfw-src/lib/win32/win32_dllmain.c +60 -0
  136. data/glfw-src/lib/win32/win32_enable.c +155 -0
  137. data/glfw-src/lib/win32/win32_fullscreen.c +317 -0
  138. data/glfw-src/lib/win32/win32_glext.c +85 -0
  139. data/glfw-src/lib/win32/win32_init.c +356 -0
  140. data/glfw-src/lib/win32/win32_joystick.c +234 -0
  141. data/glfw-src/lib/win32/win32_thread.c +511 -0
  142. data/glfw-src/lib/win32/win32_time.c +146 -0
  143. data/glfw-src/lib/win32/win32_window.c +1714 -0
  144. data/glfw-src/lib/window.c +727 -0
  145. data/glfw-src/lib/x11/Makefile.x11.in +243 -0
  146. data/glfw-src/lib/x11/platform.h +415 -0
  147. data/glfw-src/lib/x11/x11_enable.c +51 -0
  148. data/glfw-src/lib/x11/x11_fullscreen.c +524 -0
  149. data/glfw-src/lib/x11/x11_glext.c +69 -0
  150. data/glfw-src/lib/x11/x11_init.c +275 -0
  151. data/glfw-src/lib/x11/x11_joystick.c +371 -0
  152. data/glfw-src/lib/x11/x11_keysym2unicode.c +902 -0
  153. data/glfw-src/lib/x11/x11_thread.c +507 -0
  154. data/glfw-src/lib/x11/x11_time.c +154 -0
  155. data/glfw-src/lib/x11/x11_window.c +1746 -0
  156. data/glfw-src/license.txt +21 -0
  157. data/glfw-src/readme.html +927 -0
  158. data/glfw-src/support/d/examples/Makefile +59 -0
  159. data/glfw-src/support/d/examples/boing.d +610 -0
  160. data/glfw-src/support/d/examples/gears.d +379 -0
  161. data/glfw-src/support/d/examples/keytest.d +272 -0
  162. data/glfw-src/support/d/examples/listmodes.d +48 -0
  163. data/glfw-src/support/d/examples/mipmaps.d +126 -0
  164. data/glfw-src/support/d/examples/mtbench.d +304 -0
  165. data/glfw-src/support/d/examples/mthello.d +54 -0
  166. data/glfw-src/support/d/examples/particles.d +1150 -0
  167. data/glfw-src/support/d/examples/pong3d.d +840 -0
  168. data/glfw-src/support/d/examples/splitview.d +486 -0
  169. data/glfw-src/support/d/examples/triangle.d +108 -0
  170. data/glfw-src/support/d/examples/wave.d +400 -0
  171. data/glfw-src/support/d/imports/gl.d +4539 -0
  172. data/glfw-src/support/d/imports/glfw.d +349 -0
  173. data/glfw-src/support/d/imports/glu.d +328 -0
  174. data/glfw-src/support/d/lib/glfwdll.def +64 -0
  175. data/glfw-src/support/d/lib/glu32.def +56 -0
  176. data/glfw-src/support/d/lib/makefile +12 -0
  177. data/glfw-src/support/d/lib/opengl32.def +372 -0
  178. data/glfw-src/support/d/readme.html +83 -0
  179. data/glfw-src/support/delphi/examples/Triangle.dpr +105 -0
  180. data/glfw-src/support/delphi/lib/glfw.pas +437 -0
  181. data/glfw-src/support/delphi/readme.html +97 -0
  182. data/glfw-src/support/lua/examples/gears.lua +383 -0
  183. data/glfw-src/support/lua/examples/test1.lua +68 -0
  184. data/glfw-src/support/lua/readme.html +128 -0
  185. data/glfw-src/support/lua/src/luaglfw.c +1179 -0
  186. data/glfw-src/support/lua/src/luaglfw.h +48 -0
  187. data/glfw-src/support/lua/src/runlua.c +82 -0
  188. data/glfw-src/support/masm/examples/fpc.mac +47 -0
  189. data/glfw-src/support/masm/examples/makeit.bat +66 -0
  190. data/glfw-src/support/masm/examples/triangle.asm +232 -0
  191. data/glfw-src/support/masm/include/glfw.inc +326 -0
  192. data/glfw-src/support/masm/include/glu32.inc +55 -0
  193. data/glfw-src/support/masm/include/opengl32.inc +372 -0
  194. data/glfw-src/support/masm/lib/glfwdll.lib +0 -0
  195. data/glfw-src/support/masm/readme.html +170 -0
  196. data/glfw-src/support/msvc80/GLFW.sln +26 -0
  197. data/glfw-src/support/msvc80/GLFW.vcproj +257 -0
  198. data/glfw-src/support/msvc80/GLFWDLL.vcproj +287 -0
  199. data/glfw-src/support/visualbasic/bindings/glfw.bas +320 -0
  200. data/glfw-src/support/visualbasic/bindings/glu32.bas +284 -0
  201. data/glfw-src/support/visualbasic/bindings/opengl32.bas +999 -0
  202. data/glfw-src/support/visualbasic/examples/Triangle.bas +101 -0
  203. data/glfw-src/support/visualbasic/readme.html +164 -0
  204. data/website/index.html +84 -0
  205. data/website/style.css +110 -0
  206. metadata +301 -0
@@ -0,0 +1,68 @@
1
+ --------------------------------------------------------------------------
2
+ -- Simple test program testing GLFW and OpenGL from Lua
3
+ --------------------------------------------------------------------------
4
+
5
+
6
+ local running = true
7
+
8
+
9
+ -- Key callback function
10
+ function keyfun( key, action )
11
+ if action == glfw.RELEASE then
12
+ return
13
+ end
14
+
15
+ if key == glfw.KEY_ESC then
16
+ running = false
17
+ end
18
+ end
19
+
20
+
21
+ -- Window close callback function
22
+ function closefun()
23
+ running = false
24
+ return glfw.TRUE
25
+ end
26
+
27
+
28
+ -- Main program and event loop
29
+ function main()
30
+ -- Init GLFW
31
+ if glfw.Init() ~= glfw.TRUE then
32
+ return
33
+ end
34
+
35
+ -- Open window
36
+ if glfw.OpenWindow( 640,480,0,0,0,0,24,0,glfw.WINDOW ) ~= glfw.TRUE then
37
+ glfw.Terminate()
38
+ return
39
+ end
40
+
41
+ -- Set window properties
42
+ glfw.SetWindowTitle( "Hello world!" )
43
+ glfw.Enable( glfw.KEY_REPEAT )
44
+ glfw.SwapInterval( 0 )
45
+
46
+ -- Set callback functions
47
+ glfw.SetKeyCallback( "keyfun" );
48
+ glfw.SetWindowCloseCallback( "closefun" );
49
+
50
+ while running do
51
+ -- Draw
52
+ gl.ClearColor(0,1,0,0)
53
+ gl.Clear("COLOR_BUFFER_BIT,DEPTH_BUFFER_BIT")
54
+
55
+ -- Swap buffers
56
+ glfw.SwapBuffers()
57
+ end
58
+
59
+ -- Terminate GLFW
60
+ glfw.Terminate()
61
+
62
+ -- Exit program
63
+ return
64
+ end
65
+
66
+
67
+ -- Execute!
68
+ main()
@@ -0,0 +1,128 @@
1
+ <html>
2
+
3
+ <head>
4
+ <title>GLFW Readme file for Lua</title>
5
+ </head>
6
+ <body>
7
+
8
+ <!-- TITLE -------------------------------------------------------------->
9
+ <center>
10
+ <font face="bookman old style,arial" size=+4><b>GLFW v2.5</b></font><br>
11
+ <font face="bookman old style,arial" size=+3>for Lua</font>
12
+ </center>
13
+
14
+ <!-- CONTENTS ----------------------------------------------------------->
15
+ <p>
16
+ <center>
17
+ <table border=0><tr><td>
18
+ <b>
19
+ <ol>
20
+ <li><a href="#sec1">Introduction</li></a>
21
+ <li><a href="#sec2">Compiling the luaglfw library</li></a>
22
+ <li><a href="#sec3">Using GLFW from Lua</li></a>
23
+ <li><a href="#sec4">The author</li></a>
24
+ </ol>
25
+ </b>
26
+ </td></tr></table>
27
+ </center>
28
+
29
+
30
+ <!----------------------------------------------------------------------->
31
+ <p><hr>
32
+ <!----------------------------------------------------------------------->
33
+
34
+ <a name="sec1">
35
+ <p><h2>1. Introduction</h2>
36
+
37
+ <p>This directory contains a Lua library that exposes most of the GLFW API
38
+ functionality to the Lua programming language.
39
+
40
+ <p>For further information on how to use GLFW you should read the GLFW
41
+ documentation.
42
+
43
+
44
+ <!----------------------------------------------------------------------->
45
+ <p><hr>
46
+ <!----------------------------------------------------------------------->
47
+
48
+ <a name="sec2">
49
+ <p><h2>2. Compiling the luaglfw library</h2>
50
+
51
+ <p>The GLFW interface library for Lua that you can find in the <b>src</b>
52
+ directory is a stand alone component, without any dependencies on other
53
+ Lua extensions. However it is fairly useless without Lua itself and some
54
+ kind of Lua library for OpenGL.
55
+
56
+ <p>You will most likely want to build a stand alone Lua interpreter that
57
+ is linked with the luaglfw library and some OpenGL library for Lua. If
58
+ you are doing something more advanced, such as integrating Lua into your
59
+ own C/C++ application, you probably know how to do it, so I will not go
60
+ into all the details.
61
+
62
+ <p>There is a very simple Lua interpreter included in the <b>src</b>
63
+ directory. To build it you need the following software compiled and
64
+ installed:
65
+
66
+ <ul>
67
+ <li><a href="http://glfw.sf.net/">GLFW</a> (of course)</li>
68
+ <li><a href="http://www.lua.org/">Lua</a> - A free light-weight
69
+ programming language.</li>
70
+ <li><a href="http://luagl.sourceforge.net/">LuaGL</a> - A free library
71
+ that provides access to OpenGL.</li>
72
+ </ul>
73
+
74
+ <p>With the compiled interpreter, you should be able to run the example
75
+ programs in the <b>examples</b> directory.
76
+
77
+
78
+ <!----------------------------------------------------------------------->
79
+ <p><hr>
80
+ <!----------------------------------------------------------------------->
81
+
82
+ <a name="sec3">
83
+ <p><h2>3. Using GLFW from Lua</h2>
84
+
85
+ <p>The luaglfw library has been designed to work as similar to the
86
+ original GLFW library as possible. There are a few differences though:
87
+
88
+ <ul>
89
+ <li>All function names begin with <b>glfw.</b> rather than <b>glfw</b>
90
+ (for instance glfwInit is called glfw.Init)</li>
91
+ <li>All constant names begin with <b>glfw.</b> rather than <b>GLFW_</b>
92
+ (for instance GLFW_KEY_ESC is called glfw.KEY_ESC)</li>
93
+ <li>Functions that return multiple results do so the Lua way rather
94
+ than the C way (for instance glfwGetMousePos returns two numbers
95
+ instead of taking two variable arguments)</li>
96
+ <li>Functions that deal with boolean values do <i>not</i> use Lua
97
+ booleans, but rather glfw.TURE/glfw.FALSE</li>
98
+ <li>Some functions are unsupported under Lua: glfwReadImage,
99
+ glfwFreeImage and all threading functions</li>
100
+ </ul>
101
+
102
+
103
+
104
+ <!----------------------------------------------------------------------->
105
+ <p><hr>
106
+ <!----------------------------------------------------------------------->
107
+
108
+ <a name="sec4">
109
+ <p><h2>3. The maintainer</h2>
110
+
111
+ <p>My name is Camilla Berglund,
112
+ <a href="mailto:elmindreda@users.sourceforge.net">elmindreda@users.sourceforge.net</a>.
113
+ Please visit our
114
+ <a href="http://sourceforge.net/projects/glfw/">support forums</a>
115
+ if you have any problems with GLFW or any questions concerning GLFW.
116
+
117
+ <p>The GLFW web site can be found here:
118
+ <a href="http://glfw.sourceforge.net/">http://glfw.sourceforge.net/</a>.
119
+ It contains the latest version of GLFW, news and other information that is
120
+ useful for OpenGL development.
121
+
122
+ <!----------------------------------------------------------------------->
123
+ <p><hr>
124
+ <!----------------------------------------------------------------------->
125
+
126
+ </body>
127
+ </html>
128
+
@@ -0,0 +1,1179 @@
1
+ //========================================================================
2
+ // GLFW - An OpenGL framework
3
+ // File: luaglfw.c
4
+ // Platform: Lua 5.0
5
+ // API version: 2.5
6
+ // WWW: http://glfw.sourceforge.net
7
+ //------------------------------------------------------------------------
8
+ // Copyright (c) 2002-2005 Camilla Berglund
9
+ //
10
+ // This software is provided 'as-is', without any express or implied
11
+ // warranty. In no event will the authors be held liable for any damages
12
+ // arising from the use of this software.
13
+ //
14
+ // Permission is granted to anyone to use this software for any purpose,
15
+ // including commercial applications, and to alter it and redistribute it
16
+ // freely, subject to the following restrictions:
17
+ //
18
+ // 1. The origin of this software must not be misrepresented; you must not
19
+ // claim that you wrote the original software. If you use this software
20
+ // in a product, an acknowledgment in the product documentation would
21
+ // be appreciated but is not required.
22
+ //
23
+ // 2. Altered source versions must be plainly marked as such, and must not
24
+ // be misrepresented as being the original software.
25
+ //
26
+ // 3. This notice may not be removed or altered from any source
27
+ // distribution.
28
+ //
29
+ //========================================================================
30
+
31
+ #include <lauxlib.h>
32
+ #include <GL/glfw.h>
33
+ #include "luaglfw.h"
34
+
35
+
36
+ //************************************************************************
37
+ //**** Internal type definitions ****
38
+ //************************************************************************
39
+
40
+ struct lua_constant
41
+ {
42
+ char *str;
43
+ int value;
44
+ };
45
+
46
+
47
+ //************************************************************************
48
+ //**** Handy functions ****
49
+ //************************************************************************
50
+
51
+ // Check the number of arguments on the Lua stack
52
+ static int badArgs( lua_State *L, int n, char const *name )
53
+ {
54
+ if( lua_gettop(L) != n )
55
+ {
56
+ lua_settop( L, 0 );
57
+ lua_pushstring( L, "Bad arguments passed to function: " );
58
+ lua_pushstring( L, name );
59
+ lua_concat( L, 2 );
60
+ lua_error( L );
61
+ return 1;
62
+ }
63
+ return 0;
64
+ }
65
+
66
+ // Get a numeric value from a Lua table
67
+ static void getNumber( lua_State *L, int index, char *key, lua_Number *num )
68
+ {
69
+ lua_pushstring( L, key );
70
+ if( index < 0 ) index --;
71
+ lua_rawget( L, index );
72
+ if( !lua_isnil( L, -1 ) )
73
+ {
74
+ *num = lua_tonumber( L, -1 );
75
+ }
76
+ lua_remove( L, -1 );
77
+ }
78
+
79
+ // Add constants to the table on top of the stack
80
+ static void addConstants( lua_State *L, struct lua_constant *cn )
81
+ {
82
+ while( cn->str )
83
+ {
84
+ lua_pushstring( L, cn->str );
85
+ lua_pushnumber( L, cn->value );
86
+ lua_rawset( L, -3 );
87
+ ++ cn;
88
+ }
89
+ }
90
+
91
+ // Report error for unsupported functions
92
+ static void unsupportedFunction( lua_State *L, char const *name )
93
+ {
94
+ lua_settop( L, 0 );
95
+ lua_pushstring( L, "Unsupported function: " );
96
+ lua_pushstring( L, name );
97
+ lua_concat( L, 2 );
98
+ lua_error( L );
99
+ }
100
+
101
+
102
+
103
+ //************************************************************************
104
+ //*** Callback wrapper functions ****
105
+ //************************************************************************
106
+
107
+ static lua_State * callback_lua_state = (lua_State *) 0;
108
+
109
+ static const char * windowsize_name;
110
+ static const char * windowclose_name;
111
+ static const char * windowrefresh_name;
112
+ static const char * mousebutton_name;
113
+ static const char * mousepos_name;
114
+ static const char * mousewheel_name;
115
+ static const char * key_name;
116
+ static const char * char_name;
117
+
118
+
119
+ void GLFWCALL luaglfw_windowsizefun( int w, int h )
120
+ {
121
+ lua_State *L = callback_lua_state;
122
+ if( L == NULL ) return;
123
+
124
+ lua_getglobal( L, windowsize_name );
125
+ if( lua_isfunction( L, -1 ) )
126
+ {
127
+ lua_pushnumber( L, (lua_Number)w );
128
+ lua_pushnumber( L, (lua_Number)h );
129
+ lua_pcall( L, 2, 0, 0 );
130
+ }
131
+ }
132
+
133
+ int GLFWCALL luaglfw_windowclosefun( void )
134
+ {
135
+ lua_State *L = callback_lua_state;
136
+ int do_close = 1;
137
+ if( L == NULL ) return 1;
138
+
139
+ lua_getglobal( L, windowclose_name );
140
+ if( lua_isfunction( L, -1 ) )
141
+ {
142
+ lua_pcall( L, 0, 1, 0 );
143
+ do_close = (int) lua_tonumber( L, -1 );
144
+ lua_pop( L, 1 );
145
+ }
146
+ return do_close;
147
+ }
148
+
149
+ void GLFWCALL luaglfw_windowrefreshfun( void )
150
+ {
151
+ lua_State *L = callback_lua_state;
152
+ if( L == NULL ) return;
153
+
154
+ lua_getglobal( L, windowrefresh_name );
155
+ if( lua_isfunction( L, -1 ) )
156
+ {
157
+ lua_pcall( L, 0, 0, 0 );
158
+ }
159
+ }
160
+
161
+ void GLFWCALL luaglfw_mousebuttonfun( int button, int action )
162
+ {
163
+ lua_State *L = callback_lua_state;
164
+ if( L == NULL ) return;
165
+
166
+ lua_getglobal( L, mousebutton_name );
167
+ if( lua_isfunction( L, -1 ) )
168
+ {
169
+ lua_pushnumber( L, (lua_Number)button );
170
+ lua_pushnumber( L, (lua_Number)action );
171
+ lua_pcall( L, 2, 0, 0 );
172
+ }
173
+ }
174
+
175
+ void GLFWCALL luaglfw_mouseposfun( int x, int y )
176
+ {
177
+ lua_State *L = callback_lua_state;
178
+ if( L == NULL ) return;
179
+
180
+ lua_getglobal( L, mousepos_name );
181
+ if( lua_isfunction( L, -1 ) )
182
+ {
183
+ lua_pushnumber( L, (lua_Number)x );
184
+ lua_pushnumber( L, (lua_Number)y );
185
+ lua_pcall( L, 2, 0, 0 );
186
+ }
187
+ }
188
+
189
+ void GLFWCALL luaglfw_mousewheelfun( int wheelpos )
190
+ {
191
+ lua_State *L = callback_lua_state;
192
+ if( L == NULL ) return;
193
+
194
+ lua_getglobal( L, mousewheel_name );
195
+ if( lua_isfunction( L, -1 ) )
196
+ {
197
+ lua_pushnumber( L, (lua_Number)wheelpos );
198
+ lua_pcall( L, 1, 0, 0 );
199
+ }
200
+ }
201
+
202
+ void GLFWCALL luaglfw_keyfun( int key, int action )
203
+ {
204
+ lua_State *L = callback_lua_state;
205
+ if( L == NULL ) return;
206
+
207
+ lua_getglobal( L, key_name );
208
+ if( lua_isfunction( L, -1 ) )
209
+ {
210
+ lua_pushnumber( L, (lua_Number)key );
211
+ lua_pushnumber( L, (lua_Number)action );
212
+ lua_pcall( L, 2, 0, 0 );
213
+ }
214
+ }
215
+
216
+ void GLFWCALL luaglfw_charfun( int key, int action )
217
+ {
218
+ lua_State *L = callback_lua_state;
219
+ if( L == NULL ) return;
220
+
221
+ lua_getglobal( L, char_name );
222
+ if( lua_isfunction( L, -1 ) )
223
+ {
224
+ lua_pushnumber( L, (lua_Number)key );
225
+ lua_pushnumber( L, (lua_Number)action );
226
+ lua_pcall( L, 2, 0, 0 );
227
+ }
228
+ }
229
+
230
+
231
+
232
+ //************************************************************************
233
+ //**** GLFW proxy functions ****
234
+ //************************************************************************
235
+
236
+
237
+ //========================================================================
238
+ // Init/termination & version info
239
+ //========================================================================
240
+
241
+ static int glfw_Init( lua_State *L )
242
+ {
243
+ int res;
244
+ lua_settop( L, 0 );
245
+ res = glfwInit();
246
+ lua_pushnumber( L, (lua_Number)res );
247
+ return 1;
248
+ }
249
+
250
+ static int glfw_Terminate( lua_State *L )
251
+ {
252
+ glfwTerminate();
253
+ return 0;
254
+ }
255
+
256
+ static int glfw_GetVersion( lua_State *L )
257
+ {
258
+ int major, minor, rev;
259
+ glfwGetVersion( &major, &minor, &rev );
260
+ lua_pushnumber( L, major );
261
+ lua_pushnumber( L, minor );
262
+ lua_pushnumber( L, rev );
263
+ return 3;
264
+ }
265
+
266
+
267
+ //========================================================================
268
+ // Window handling
269
+ //========================================================================
270
+
271
+ static int glfw_OpenWindow( lua_State *L )
272
+ {
273
+ lua_Number w, h, r, g, b, a, depth, stencil, mode;
274
+ int argc, res;
275
+
276
+ // Check arguments
277
+ if( badArgs( L, 9, "OpenWindow" ) ) return 0;
278
+
279
+ // Get all arguments to glfwOpenWindow
280
+ w = lua_tonumber( L, 1 );
281
+ h = lua_tonumber( L, 2 );
282
+ r = lua_tonumber( L, 3 );
283
+ g = lua_tonumber( L, 4 );
284
+ b = lua_tonumber( L, 5 );
285
+ a = lua_tonumber( L, 6 );
286
+ depth = lua_tonumber( L, 7 );
287
+ stencil = lua_tonumber( L, 8 );
288
+ mode = lua_tonumber( L, 9 );
289
+
290
+ // Call glfwOpenWindow
291
+ lua_settop( L,0 );
292
+ res = glfwOpenWindow( (int)w, (int)h, (int)r, (int)g, (int)b,
293
+ (int)a, (int)depth, (int)stencil,
294
+ (int)mode );
295
+
296
+ // Return result
297
+ lua_pushnumber( L, (lua_Number)res );
298
+ return 1;
299
+ }
300
+
301
+ static int glfw_OpenWindowHint( lua_State *L )
302
+ {
303
+ lua_Number target, hint;
304
+ if( badArgs( L, 2, "OpenWindowHint" ) ) return 0;
305
+ target = lua_tonumber( L, 1 );
306
+ hint = lua_tonumber( L, 2 );
307
+ lua_settop( L, 0 );
308
+ glfwOpenWindowHint( (int)target, (int)hint );
309
+ return 0;
310
+ }
311
+
312
+ static int glfw_CloseWindow( lua_State *L )
313
+ {
314
+ glfwCloseWindow();
315
+ return 0;
316
+ }
317
+
318
+ static int glfw_SetWindowTitle( lua_State *L )
319
+ {
320
+ const char *str;
321
+ if( badArgs( L, 1, "SetWindowTitle" ) ) return 0;
322
+ str = lua_tostring( L, 1 );
323
+ lua_remove( L, 1 );
324
+ glfwSetWindowTitle( str );
325
+ return 0;
326
+ }
327
+
328
+ static int glfw_SetWindowSize( lua_State *L )
329
+ {
330
+ lua_Number w, h;
331
+ if( badArgs( L, 2, "SetWindowSize" ) ) return 0;
332
+ w = lua_tonumber( L, 1 );
333
+ h = lua_tonumber( L, 2 );
334
+ lua_settop( L, 0 );
335
+ glfwSetWindowSize( (int)w, (int)h );
336
+ return 0;
337
+ }
338
+
339
+ static int glfw_GetWindowSize( lua_State *L )
340
+ {
341
+ int w, h;
342
+ glfwGetWindowSize( &w, &h );
343
+ lua_settop( L, 0 );
344
+ lua_pushnumber( L, (lua_Number)w );
345
+ lua_pushnumber( L, (lua_Number)h );
346
+ return 2;
347
+ }
348
+
349
+ static int glfw_SetWindowPos( lua_State *L )
350
+ {
351
+ lua_Number x, y;
352
+ if( badArgs( L, 2, "SetWindowPos" ) ) return 0;
353
+ x = lua_tonumber( L, 1 );
354
+ y = lua_tonumber( L, 2 );
355
+ lua_settop( L, 0 );
356
+ glfwSetWindowPos( (int)x, (int)y );
357
+ return 0;
358
+ }
359
+
360
+ static int glfw_IconifyWindow( lua_State *L )
361
+ {
362
+ glfwIconifyWindow();
363
+ return 0;
364
+ }
365
+
366
+ static int glfw_RestoreWindow( lua_State *L )
367
+ {
368
+ glfwRestoreWindow();
369
+ return 0;
370
+ }
371
+
372
+ static int glfw_GetWindowParam( lua_State *L )
373
+ {
374
+ lua_Number n;
375
+ if( badArgs( L, 1, "GetWindowParam" ) ) return 0;
376
+ n = lua_tonumber( L, 1 );
377
+ lua_settop( L, 0 );
378
+ n = glfwGetWindowParam( (int)n );
379
+ lua_pushnumber( L, n );
380
+ return 1;
381
+ }
382
+
383
+
384
+
385
+ //========================================================================
386
+ // Buffer swapping
387
+ //========================================================================
388
+
389
+ static int glfw_SwapBuffers( lua_State *L )
390
+ {
391
+ glfwSwapBuffers();
392
+ return 0;
393
+ }
394
+
395
+ static int glfw_SwapInterval( lua_State *L )
396
+ {
397
+ lua_Number interval;
398
+ if( badArgs( L, 1, "SwapInterval" ) ) return 0;
399
+ interval = lua_tonumber( L, 1 );
400
+ lua_remove( L, 1 );
401
+ glfwSwapInterval( (int)interval );
402
+ return 0;
403
+ }
404
+
405
+
406
+ //========================================================================
407
+ // Video modes
408
+ //========================================================================
409
+
410
+ static int glfw_GetVideoModes( lua_State *L )
411
+ {
412
+ // !!TODO!!
413
+ unsupportedFunction( L, "GetVideoModes" );
414
+ return 0;
415
+ }
416
+
417
+ static int glfw_GetDesktopMode( lua_State *L )
418
+ {
419
+ GLFWvidmode mode;
420
+ glfwGetDesktopMode( &mode );
421
+
422
+ lua_newtable( L );
423
+ lua_pushstring( L, "Width" );
424
+ lua_pushnumber( L, mode.Width );
425
+ lua_rawset( L, -3 );
426
+ lua_pushstring( L, "Height" );
427
+ lua_pushnumber( L, mode.Height );
428
+ lua_rawset( L, -3 );
429
+
430
+ return 1;
431
+ }
432
+
433
+
434
+ //========================================================================
435
+ // Event polling/waiting
436
+ //========================================================================
437
+
438
+ static int glfw_PollEvents( lua_State *L )
439
+ {
440
+ glfwPollEvents();
441
+ return 0;
442
+ }
443
+
444
+ static int glfw_WaitEvents( lua_State *L )
445
+ {
446
+ glfwWaitEvents();
447
+ return 0;
448
+ }
449
+
450
+
451
+ //========================================================================
452
+ // Key and mouse input
453
+ //========================================================================
454
+
455
+ static int glfw_GetKey( lua_State *L )
456
+ {
457
+ int n = 0;
458
+
459
+ if( badArgs( L, 1, "GetKey" ) ) return 0;
460
+
461
+ switch( lua_type( L, 1 ) )
462
+ {
463
+ case LUA_TSTRING:
464
+ n = (lua_tostring(L,1)[0]);
465
+ break;
466
+
467
+ case LUA_TNUMBER:
468
+ n = lua_tonumber(L,1);
469
+ break;
470
+ }
471
+
472
+ lua_settop( L, 0 );
473
+ n = glfwGetKey( n );
474
+ lua_pushnumber( L, n );
475
+ return 1;
476
+ }
477
+
478
+ static int glfw_GetMouseButton( lua_State *L )
479
+ {
480
+ lua_Number n;
481
+ if( badArgs( L, 1, "GetMouseButton" ) ) return 0;
482
+ n = lua_tonumber( L, 1 );
483
+ lua_settop( L, 0 );
484
+ lua_pushnumber( L, glfwGetMouseButton( (int)n ) );
485
+ return 1;
486
+ }
487
+
488
+ static int glfw_GetMousePos( lua_State *L )
489
+ {
490
+ int x, y;
491
+ glfwGetMousePos( &x, &y );
492
+ lua_settop( L, 0 );
493
+ lua_pushnumber( L, (lua_Number)x );
494
+ lua_pushnumber( L, (lua_Number)y );
495
+ return 2;
496
+ }
497
+
498
+ static int glfw_SetMousePos( lua_State *L )
499
+ {
500
+ lua_Number x, y;
501
+ if( badArgs( L, 2, "SetMousePos" ) ) return 0;
502
+ x = lua_tonumber( L, 1 );
503
+ y = lua_tonumber( L, 2 );
504
+ lua_settop( L, 0 );
505
+ glfwSetMousePos( (int)x, (int)y );
506
+ return 0;
507
+ }
508
+
509
+ static int glfw_GetMouseWheel( lua_State *L )
510
+ {
511
+ int pos;
512
+ pos = glfwGetMouseWheel();
513
+ lua_settop( L, 0 );
514
+ lua_pushnumber( L, (lua_Number)pos );
515
+ return 1;
516
+ }
517
+
518
+ static int glfw_SetMouseWheel( lua_State *L )
519
+ {
520
+ lua_Number pos;
521
+ if( badArgs( L, 1, "SetMouseWheel" ) ) return 0;
522
+ pos = lua_tonumber( L, 1 );
523
+ lua_settop( L, 0 );
524
+ glfwSetMouseWheel( (int)pos );
525
+ return 0;
526
+ }
527
+
528
+
529
+ //========================================================================
530
+ // Joystick input
531
+ //========================================================================
532
+
533
+ static int glfw_GetJoystickParam( lua_State *L )
534
+ {
535
+ lua_Number joy, param;
536
+ int res;
537
+ if( badArgs( L, 2, "GetJoystickParam" ) ) return 0;
538
+ joy = lua_tonumber( L, 1 );
539
+ param = lua_tonumber( L, 2 );
540
+ lua_settop( L, 0 );
541
+ res = glfwGetJoystickParam( (int)joy, (int)param );
542
+ lua_pushnumber( L, (lua_Number)res );
543
+ return 1;
544
+ }
545
+
546
+ #define LUAGLFW_MAX_JOY_AXES 256
547
+
548
+ static int glfw_GetJoystickPos( lua_State *L )
549
+ {
550
+ int joy, numaxes, res, i;
551
+ float pos[ LUAGLFW_MAX_JOY_AXES ];
552
+
553
+ // Get arguments
554
+ if( badArgs( L, 2, "GetJoystickPos" ) ) return 0;
555
+ joy = (int)lua_tonumber( L, 1 );
556
+ numaxes = (int)lua_tonumber( L, 2 );
557
+ lua_settop( L, 0 );
558
+ if( numaxes < 1 ) return 0;
559
+ if( numaxes > LUAGLFW_MAX_JOY_AXES ) numaxes = LUAGLFW_MAX_JOY_AXES;
560
+
561
+ // Call GLFW funciton
562
+ res = glfwGetJoystickPos( joy, pos, numaxes );
563
+
564
+ // Create result array
565
+ lua_newtable( L );
566
+ for( i = 0; i < res; ++ i )
567
+ {
568
+ lua_pushnumber( L, (lua_Number)(i+1) );
569
+ lua_pushnumber( L, pos[ i ] );
570
+ lua_rawset( L, -3 );
571
+ }
572
+
573
+ return 1;
574
+ }
575
+
576
+ #define LUAGLFW_MAX_JOY_BUTTONS 256
577
+
578
+ static int glfw_GetJoystickButtons( lua_State *L )
579
+ {
580
+ int joy, numbuttons, res, i;
581
+ unsigned char buttons[ LUAGLFW_MAX_JOY_AXES ];
582
+
583
+ // Get arguments
584
+ if( badArgs( L, 2, "GetJoystickButtons" ) ) return 0;
585
+ joy = (int)lua_tonumber( L, 1 );
586
+ numbuttons = (int)lua_tonumber( L, 2 );
587
+ lua_settop( L, 0 );
588
+ if( numbuttons < 1 ) return 0;
589
+ if( numbuttons > LUAGLFW_MAX_JOY_BUTTONS )
590
+ numbuttons = LUAGLFW_MAX_JOY_BUTTONS;
591
+
592
+ // Call GLFW funciton
593
+ res = glfwGetJoystickButtons( joy, buttons, numbuttons );
594
+
595
+ // Create result array
596
+ lua_newtable( L );
597
+ for( i = 0; i < res; ++ i )
598
+ {
599
+ lua_pushnumber( L, (lua_Number)(i+1) );
600
+ lua_pushnumber( L, (lua_Number)buttons[ i ] );
601
+ lua_rawset( L, -3 );
602
+ }
603
+
604
+ return 1;
605
+ }
606
+
607
+
608
+ //========================================================================
609
+ // Timing
610
+ //========================================================================
611
+
612
+ static int glfw_GetTime( lua_State *L )
613
+ {
614
+ lua_Number t;
615
+ t = glfwGetTime();
616
+ lua_settop( L, 0 );
617
+ lua_pushnumber( L, t );
618
+ return 1;
619
+ }
620
+
621
+ static int glfw_SetTime( lua_State *L )
622
+ {
623
+ lua_Number t;
624
+ if ( badArgs( L, 1, "SetTime" ) ) return 0;
625
+ t = lua_tonumber( L, 1 );
626
+ lua_settop( L, 0 );
627
+ glfwSetTime( (double)t );
628
+ return 0;
629
+ }
630
+
631
+ static int glfw_Sleep( lua_State *L )
632
+ {
633
+ lua_Number t;
634
+ if ( badArgs( L, 1, "Sleep" ) ) return 0;
635
+ t = lua_tonumber( L, 1 );
636
+ lua_settop( L, 0 );
637
+ glfwSleep( (double)t );
638
+ return 0;
639
+ }
640
+
641
+
642
+ //========================================================================
643
+ // Threading support (not possible in Lua)
644
+ //========================================================================
645
+
646
+ static int glfw_CreateThread( lua_State *L )
647
+ {
648
+ unsupportedFunction( L, "CreateThread" );
649
+ return 0;
650
+ }
651
+
652
+ static int glfw_DestroyThread( lua_State *L )
653
+ {
654
+ unsupportedFunction( L, "DestroyThread" );
655
+ return 0;
656
+ }
657
+
658
+ static int glfw_WaitThread( lua_State *L )
659
+ {
660
+ unsupportedFunction( L, "WaitThread" );
661
+ return 0;
662
+ }
663
+
664
+ static int glfw_GetThreadID( lua_State *L )
665
+ {
666
+ unsupportedFunction( L, "GetThreadID" );
667
+ return 0;
668
+ }
669
+
670
+ static int glfw_CreateMutex( lua_State *L )
671
+ {
672
+ unsupportedFunction( L, "CreateMutex" );
673
+ return 0;
674
+ }
675
+
676
+ static int glfw_DestroyMutex( lua_State *L )
677
+ {
678
+ unsupportedFunction( L, "DestroyMutex" );
679
+ return 0;
680
+ }
681
+
682
+ static int glfw_LockMutex( lua_State *L )
683
+ {
684
+ unsupportedFunction( L, "LockMutex" );
685
+ return 0;
686
+ }
687
+
688
+ static int glfw_UnlockMutex( lua_State *L )
689
+ {
690
+ unsupportedFunction( L, "UnlockMutex" );
691
+ return 0;
692
+ }
693
+
694
+ static int glfw_CreateCond( lua_State *L )
695
+ {
696
+ unsupportedFunction( L, "CreateCond" );
697
+ return 0;
698
+ }
699
+
700
+ static int glfw_DestroyCond( lua_State *L )
701
+ {
702
+ unsupportedFunction( L, "DestroyCond" );
703
+ return 0;
704
+ }
705
+
706
+ static int glfw_WaitCond( lua_State *L )
707
+ {
708
+ unsupportedFunction( L, "WaitCond" );
709
+ return 0;
710
+ }
711
+
712
+ static int glfw_SignalCond( lua_State *L )
713
+ {
714
+ unsupportedFunction( L, "SignalCond" );
715
+ return 0;
716
+ }
717
+
718
+ static int glfw_BroadcastCond( lua_State *L )
719
+ {
720
+ unsupportedFunction( L, "BroadcastCond" );
721
+ return 0;
722
+ }
723
+
724
+ static int glfw_GetNumberOfProcessors( lua_State *L )
725
+ {
726
+ int n;
727
+ n = glfwGetNumberOfProcessors();
728
+ lua_settop( L,0 );
729
+ lua_pushnumber( L, (lua_Number)n );
730
+ return 1;
731
+ }
732
+
733
+
734
+ //========================================================================
735
+ // Extension handling
736
+ //========================================================================
737
+
738
+ static int glfw_GetGLVersion( lua_State *L )
739
+ {
740
+ int major, minor, rev;
741
+ glfwGetGLVersion( &major, &minor, &rev );
742
+ lua_settop( L,0 );
743
+ lua_pushnumber( L, (lua_Number)major );
744
+ lua_pushnumber( L, (lua_Number)minor );
745
+ lua_pushnumber( L, (lua_Number)rev );
746
+ return 3;
747
+ }
748
+
749
+ static int glfw_ExtensionSupported( lua_State *L )
750
+ {
751
+ const char *str;
752
+ int res;
753
+ if( badArgs( L, 1, "ExtensionSupported" ) ) return 0;
754
+ str = lua_tostring( L, 1 );
755
+ lua_settop( L, 0 );
756
+ res = glfwExtensionSupported( str );
757
+ lua_pushnumber( L, (lua_Number)res );
758
+ return 1;
759
+ }
760
+
761
+
762
+ //========================================================================
763
+ // Enable/Disable
764
+ //========================================================================
765
+
766
+ static int glfw_Enable( lua_State *L )
767
+ {
768
+ lua_Number param;
769
+ if ( badArgs( L, 1, "Enable" ) ) return 0;
770
+ param = lua_tonumber( L, 1 );
771
+ lua_settop( L, 0 );
772
+ glfwEnable( (int)param );
773
+ return 0;
774
+ }
775
+
776
+ static int glfw_Disable( lua_State *L )
777
+ {
778
+ lua_Number param;
779
+ if ( badArgs( L, 1, "Disable" ) ) return 0;
780
+ param = lua_tonumber( L, 1 );
781
+ lua_settop( L, 0 );
782
+ glfwDisable( (int)param );
783
+ return 0;
784
+ }
785
+
786
+
787
+ //========================================================================
788
+ // Image/texture I/O support
789
+ //========================================================================
790
+
791
+ static int glfw_ReadImage( lua_State *L )
792
+ {
793
+ unsupportedFunction( L, "ReadImage" );
794
+ return 0;
795
+ }
796
+
797
+ static int glfw_FreeImage( lua_State *L )
798
+ {
799
+ unsupportedFunction( L, "FreeImage" );
800
+ return 0;
801
+ }
802
+
803
+ static int glfw_LoadTexture2D( lua_State *L )
804
+ {
805
+ const char *name;
806
+ lua_Number flags;
807
+ int res;
808
+ if( badArgs( L, 2, "LoadTexture2D" ) ) return 0;
809
+ name = lua_tostring( L, 1 );
810
+ flags = lua_tonumber( L, 2 );
811
+ lua_settop( L, 0 );
812
+ res = glfwLoadTexture2D( name, (int)flags );
813
+ lua_pushnumber( L, (lua_Number)res );
814
+ return 1;
815
+ }
816
+
817
+
818
+ //========================================================================
819
+ // Callback function management
820
+ //========================================================================
821
+
822
+ static int glfw_SetWindowSizeCallback( lua_State *L )
823
+ {
824
+ GLFWwindowsizefun fun = NULL;
825
+ if( lua_isstring( L, 1 ) )
826
+ {
827
+ windowsize_name = lua_tostring( L, 1 );
828
+ fun = luaglfw_windowsizefun;
829
+ }
830
+ glfwSetWindowSizeCallback( fun );
831
+ return 0;
832
+ }
833
+
834
+ static int glfw_SetWindowCloseCallback( lua_State *L )
835
+ {
836
+ GLFWwindowclosefun fun = NULL;
837
+ if( lua_isstring( L, 1 ) )
838
+ {
839
+ windowclose_name = lua_tostring( L, 1 );
840
+ fun = luaglfw_windowclosefun;
841
+ }
842
+ glfwSetWindowCloseCallback( fun );
843
+ return 0;
844
+ }
845
+
846
+ static int glfw_SetWindowRefreshCallback( lua_State *L )
847
+ {
848
+ GLFWwindowrefreshfun fun = NULL;
849
+ if( lua_isstring( L, 1 ) )
850
+ {
851
+ windowrefresh_name = lua_tostring( L, 1 );
852
+ fun = luaglfw_windowrefreshfun;
853
+ }
854
+ glfwSetWindowRefreshCallback( fun );
855
+ return 0;
856
+ }
857
+
858
+ static int glfw_SetMouseButtonCallback( lua_State *L )
859
+ {
860
+ GLFWmousebuttonfun fun = NULL;
861
+ if( lua_isstring( L, 1 ) )
862
+ {
863
+ mousebutton_name = lua_tostring( L, 1 );
864
+ fun = luaglfw_mousebuttonfun;
865
+ }
866
+ glfwSetMouseButtonCallback( fun );
867
+ return 0;
868
+ }
869
+
870
+ static int glfw_SetMousePosCallback( lua_State *L )
871
+ {
872
+ GLFWmouseposfun fun = NULL;
873
+ if( lua_isstring( L, 1 ) )
874
+ {
875
+ mousepos_name = lua_tostring( L, 1 );
876
+ fun = luaglfw_mouseposfun;
877
+ }
878
+ glfwSetMousePosCallback( fun );
879
+ return 0;
880
+ }
881
+
882
+ static int glfw_SetMouseWheelCallback( lua_State *L )
883
+ {
884
+ GLFWmousewheelfun fun = NULL;
885
+ if( lua_isstring( L, 1 ) )
886
+ {
887
+ mousewheel_name = lua_tostring( L, 1 );
888
+ fun = luaglfw_mousewheelfun;
889
+ }
890
+ glfwSetMouseWheelCallback( fun );
891
+ return 0;
892
+ }
893
+
894
+ static int glfw_SetKeyCallback( lua_State *L )
895
+ {
896
+ GLFWkeyfun fun = NULL;
897
+ if( lua_isstring( L, 1 ) )
898
+ {
899
+ key_name = lua_tostring( L, 1 );
900
+ fun = luaglfw_keyfun;
901
+ }
902
+ glfwSetKeyCallback( fun );
903
+ return 0;
904
+ }
905
+
906
+ static int glfw_SetCharCallback( lua_State *L )
907
+ {
908
+ GLFWcharfun fun = NULL;
909
+ if( lua_isstring( L, 1 ) )
910
+ {
911
+ char_name = lua_tostring( L, 1 );
912
+ fun = luaglfw_charfun;
913
+ }
914
+ glfwSetCharCallback( fun );
915
+ return 0;
916
+ }
917
+
918
+
919
+
920
+ //************************************************************************
921
+ //**** LUA Library Registration ****
922
+ //************************************************************************
923
+
924
+ // GLFW constants are stored in the global Lua table "glfw"
925
+ static struct lua_constant glfw_constants[] =
926
+ {
927
+ // GL constants (GL_TRUE/GL_FALSE)
928
+ { "TRUE", GL_TRUE },
929
+ { "FALSE", GL_FALSE },
930
+
931
+ // GLFW version
932
+ { "VERSION_MAJOR", GLFW_VERSION_MAJOR },
933
+ { "VERSION_MINOR", GLFW_VERSION_MINOR },
934
+ { "VERSION_REVISION", GLFW_VERSION_REVISION },
935
+
936
+ // Key and button state/action definitions
937
+ { "PRESS", GLFW_PRESS },
938
+ { "RELEASE", GLFW_RELEASE },
939
+
940
+ // Keyboard key definitions
941
+ { "KEY_SPACE", GLFW_KEY_SPACE },
942
+ { "KEY_SPECIAL", GLFW_KEY_SPECIAL },
943
+ { "KEY_ESC", GLFW_KEY_ESC },
944
+ { "KEY_F1", GLFW_KEY_F1 },
945
+ { "KEY_F2", GLFW_KEY_F2 },
946
+ { "KEY_F3", GLFW_KEY_F3 },
947
+ { "KEY_F4", GLFW_KEY_F4 },
948
+ { "KEY_F5", GLFW_KEY_F5 },
949
+ { "KEY_F6", GLFW_KEY_F6 },
950
+ { "KEY_F7", GLFW_KEY_F7 },
951
+ { "KEY_F8", GLFW_KEY_F8 },
952
+ { "KEY_F9", GLFW_KEY_F9 },
953
+ { "KEY_F10", GLFW_KEY_F10 },
954
+ { "KEY_F11", GLFW_KEY_F11 },
955
+ { "KEY_F12", GLFW_KEY_F12 },
956
+ { "KEY_F13", GLFW_KEY_F13 },
957
+ { "KEY_F14", GLFW_KEY_F14 },
958
+ { "KEY_F15", GLFW_KEY_F15 },
959
+ { "KEY_F16", GLFW_KEY_F16 },
960
+ { "KEY_F17", GLFW_KEY_F17 },
961
+ { "KEY_F18", GLFW_KEY_F18 },
962
+ { "KEY_F19", GLFW_KEY_F19 },
963
+ { "KEY_F20", GLFW_KEY_F20 },
964
+ { "KEY_F21", GLFW_KEY_F21 },
965
+ { "KEY_F22", GLFW_KEY_F22 },
966
+ { "KEY_F23", GLFW_KEY_F23 },
967
+ { "KEY_F24", GLFW_KEY_F24 },
968
+ { "KEY_F25", GLFW_KEY_F25 },
969
+ { "KEY_UP", GLFW_KEY_UP },
970
+ { "KEY_DOWN", GLFW_KEY_DOWN },
971
+ { "KEY_LEFT", GLFW_KEY_LEFT },
972
+ { "KEY_RIGHT", GLFW_KEY_RIGHT },
973
+ { "KEY_LSHIFT", GLFW_KEY_LSHIFT },
974
+ { "KEY_RSHIFT", GLFW_KEY_RSHIFT },
975
+ { "KEY_LCTRL", GLFW_KEY_LCTRL },
976
+ { "KEY_RCTRL", GLFW_KEY_RCTRL },
977
+ { "KEY_LALT", GLFW_KEY_LALT },
978
+ { "KEY_RALT", GLFW_KEY_RALT },
979
+ { "KEY_TAB", GLFW_KEY_TAB },
980
+ { "KEY_ENTER", GLFW_KEY_ENTER },
981
+ { "KEY_BACKSPACE", GLFW_KEY_BACKSPACE },
982
+ { "KEY_INSERT", GLFW_KEY_INSERT },
983
+ { "KEY_DEL", GLFW_KEY_DEL },
984
+ { "KEY_PAGEUP", GLFW_KEY_PAGEUP },
985
+ { "KEY_PAGEDOWN", GLFW_KEY_PAGEDOWN },
986
+ { "KEY_HOME", GLFW_KEY_HOME },
987
+ { "KEY_END", GLFW_KEY_END },
988
+ { "KEY_KP_0", GLFW_KEY_KP_0 },
989
+ { "KEY_KP_1", GLFW_KEY_KP_1 },
990
+ { "KEY_KP_2", GLFW_KEY_KP_2 },
991
+ { "KEY_KP_3", GLFW_KEY_KP_3 },
992
+ { "KEY_KP_4", GLFW_KEY_KP_4 },
993
+ { "KEY_KP_5", GLFW_KEY_KP_5 },
994
+ { "KEY_KP_6", GLFW_KEY_KP_6 },
995
+ { "KEY_KP_7", GLFW_KEY_KP_7 },
996
+ { "KEY_KP_8", GLFW_KEY_KP_8 },
997
+ { "KEY_KP_9", GLFW_KEY_KP_9 },
998
+ { "KEY_KP_DIVIDE", GLFW_KEY_KP_DIVIDE },
999
+ { "KEY_KP_MULTIPLY", GLFW_KEY_KP_MULTIPLY },
1000
+ { "KEY_KP_SUBTRACT", GLFW_KEY_KP_SUBTRACT },
1001
+ { "KEY_KP_ADD", GLFW_KEY_KP_ADD },
1002
+ { "KEY_KP_DECIMAL", GLFW_KEY_KP_DECIMAL },
1003
+ { "KEY_KP_EQUAL", GLFW_KEY_KP_EQUAL },
1004
+ { "KEY_KP_ENTER", GLFW_KEY_KP_ENTER },
1005
+ { "KEY_LAST", GLFW_KEY_LAST },
1006
+
1007
+ // Mouse button definitions
1008
+ { "MOUSE_BUTTON_1", GLFW_MOUSE_BUTTON_1 },
1009
+ { "MOUSE_BUTTON_2", GLFW_MOUSE_BUTTON_2 },
1010
+ { "MOUSE_BUTTON_3", GLFW_MOUSE_BUTTON_3 },
1011
+ { "MOUSE_BUTTON_4", GLFW_MOUSE_BUTTON_4 },
1012
+ { "MOUSE_BUTTON_5", GLFW_MOUSE_BUTTON_5 },
1013
+ { "MOUSE_BUTTON_6", GLFW_MOUSE_BUTTON_6 },
1014
+ { "MOUSE_BUTTON_7", GLFW_MOUSE_BUTTON_7 },
1015
+ { "MOUSE_BUTTON_8", GLFW_MOUSE_BUTTON_8 },
1016
+ { "MOUSE_BUTTON_LAST", GLFW_MOUSE_BUTTON_LAST },
1017
+
1018
+ // Mouse button aliases
1019
+ { "MOUSE_BUTTON_LEFT", GLFW_MOUSE_BUTTON_LEFT },
1020
+ { "MOUSE_BUTTON_RIGHT", GLFW_MOUSE_BUTTON_RIGHT },
1021
+ { "MOUSE_BUTTON_MIDDLE", GLFW_MOUSE_BUTTON_MIDDLE },
1022
+
1023
+ // Joystick identifiers
1024
+ { "JOYSTICK_1", GLFW_JOYSTICK_1 },
1025
+ { "JOYSTICK_2", GLFW_JOYSTICK_2 },
1026
+ { "JOYSTICK_3", GLFW_JOYSTICK_3 },
1027
+ { "JOYSTICK_4", GLFW_JOYSTICK_4 },
1028
+ { "JOYSTICK_5", GLFW_JOYSTICK_5 },
1029
+ { "JOYSTICK_6", GLFW_JOYSTICK_6 },
1030
+ { "JOYSTICK_7", GLFW_JOYSTICK_7 },
1031
+ { "JOYSTICK_8", GLFW_JOYSTICK_8 },
1032
+ { "JOYSTICK_9", GLFW_JOYSTICK_9 },
1033
+ { "JOYSTICK_10", GLFW_JOYSTICK_10 },
1034
+ { "JOYSTICK_11", GLFW_JOYSTICK_11 },
1035
+ { "JOYSTICK_12", GLFW_JOYSTICK_12 },
1036
+ { "JOYSTICK_13", GLFW_JOYSTICK_13 },
1037
+ { "JOYSTICK_14", GLFW_JOYSTICK_14 },
1038
+ { "JOYSTICK_15", GLFW_JOYSTICK_15 },
1039
+ { "JOYSTICK_16", GLFW_JOYSTICK_16 },
1040
+ { "JOYSTICK_LAST", GLFW_JOYSTICK_LAST },
1041
+
1042
+ // glfwOpenWindow modes
1043
+ { "WINDOW", GLFW_WINDOW },
1044
+ { "FULLSCREEN", GLFW_FULLSCREEN },
1045
+
1046
+ // glfwGetWindowParam tokens
1047
+ { "OPENED", GLFW_OPENED },
1048
+ { "ACTIVE", GLFW_ACTIVE },
1049
+ { "ICONIFIED", GLFW_ICONIFIED },
1050
+ { "ACCELERATED", GLFW_ACCELERATED },
1051
+ { "RED_BITS", GLFW_RED_BITS },
1052
+ { "GREEN_BITS", GLFW_GREEN_BITS },
1053
+ { "BLUE_BITS", GLFW_BLUE_BITS },
1054
+ { "ALPHA_BITS", GLFW_ALPHA_BITS },
1055
+ { "DEPTH_BITS", GLFW_DEPTH_BITS },
1056
+ { "STENCIL_BITS", GLFW_STENCIL_BITS },
1057
+
1058
+ // Constants for glfwGetWindowParam and glfwOpenWindowHint
1059
+ { "REFRESH_RATE", GLFW_REFRESH_RATE },
1060
+ { "ACCUM_RED_BITS", GLFW_ACCUM_RED_BITS },
1061
+ { "ACCUM_GREEN_BITS", GLFW_ACCUM_GREEN_BITS },
1062
+ { "ACCUM_BLUE_BITS", GLFW_ACCUM_BLUE_BITS },
1063
+ { "ACCUM_ALPHA_BITS", GLFW_ACCUM_ALPHA_BITS },
1064
+ { "AUX_BUFFERS", GLFW_AUX_BUFFERS },
1065
+ { "STEREO", GLFW_STEREO },
1066
+
1067
+ // glfwEnable/glfwDisable tokens
1068
+ { "MOUSE_CURSOR", GLFW_MOUSE_CURSOR },
1069
+ { "STICKY_KEYS", GLFW_STICKY_KEYS },
1070
+ { "STICKY_MOUSE_BUTTONS", GLFW_STICKY_MOUSE_BUTTONS },
1071
+ { "SYSTEM_KEYS", GLFW_SYSTEM_KEYS },
1072
+ { "KEY_REPEAT", GLFW_KEY_REPEAT },
1073
+ { "AUTO_POLL_EVENTS", GLFW_AUTO_POLL_EVENTS },
1074
+
1075
+ // glfwWaitThread wait modes
1076
+ { "WAIT", GLFW_WAIT },
1077
+ { "NOWAIT", GLFW_NOWAIT },
1078
+
1079
+ // glfwGetJoystickParam tokens
1080
+ { "PRESENT", GLFW_PRESENT },
1081
+ { "AXES", GLFW_AXES },
1082
+ { "BUTTONS", GLFW_BUTTONS },
1083
+
1084
+ // glfwReadImage/glfwLoadTexture2D flags
1085
+ { "NO_RESCALE_BIT", GLFW_NO_RESCALE_BIT },
1086
+ { "ORIGIN_UL_BIT", GLFW_ORIGIN_UL_BIT },
1087
+ { "BUILD_MIPMAPS_BIT", GLFW_BUILD_MIPMAPS_BIT },
1088
+ { "ALPHA_MAP_BIT", GLFW_ALPHA_MAP_BIT },
1089
+
1090
+ // Time spans longer than this (seconds) are considered to be infinity
1091
+ { "INFINITY", GLFW_INFINITY },
1092
+
1093
+ { NULL, 0 }
1094
+ };
1095
+
1096
+
1097
+ // Library functions to register
1098
+ static const luaL_reg glfwlib[] = {
1099
+ { "Init", glfw_Init },
1100
+ { "Terminate", glfw_Terminate },
1101
+ { "GetVersion", glfw_GetVersion },
1102
+ { "OpenWindow", glfw_OpenWindow },
1103
+ { "OpenWindowHint", glfw_OpenWindowHint },
1104
+ { "CloseWindow", glfw_CloseWindow },
1105
+ { "SetWindowTitle", glfw_SetWindowTitle },
1106
+ { "SetWindowSize", glfw_SetWindowSize },
1107
+ { "GetWindowSize", glfw_GetWindowSize },
1108
+ { "SetWindowPos", glfw_SetWindowPos },
1109
+ { "IconifyWindow", glfw_IconifyWindow },
1110
+ { "RestoreWindow", glfw_RestoreWindow },
1111
+ { "GetWindowParam", glfw_GetWindowParam },
1112
+ { "SwapBuffers", glfw_SwapBuffers },
1113
+ { "SwapInterval", glfw_SwapInterval },
1114
+ { "GetVideoModes", glfw_GetVideoModes },
1115
+ { "GetDesktopMode", glfw_GetDesktopMode },
1116
+ { "PollEvents", glfw_PollEvents },
1117
+ { "WaitEvents", glfw_WaitEvents },
1118
+ { "GetKey", glfw_GetKey },
1119
+ { "GetMouseButton", glfw_GetMouseButton },
1120
+ { "GetMousePos", glfw_GetMousePos },
1121
+ { "SetMousePos", glfw_SetMousePos },
1122
+ { "GetMouseWheel", glfw_GetMouseWheel },
1123
+ { "SetMouseWheel", glfw_SetMouseWheel },
1124
+ { "GetJoystickParam", glfw_GetJoystickParam },
1125
+ { "GetJoystickPos", glfw_GetJoystickPos },
1126
+ { "GetJoystickButtons", glfw_GetJoystickButtons },
1127
+ { "GetTime", glfw_GetTime },
1128
+ { "SetTime", glfw_SetTime },
1129
+ { "Sleep", glfw_Sleep },
1130
+ { "GetGLVersion", glfw_GetGLVersion },
1131
+ { "ExtensionSupported", glfw_ExtensionSupported },
1132
+ { "CreateThread", glfw_CreateThread },
1133
+ { "DestroyThread", glfw_DestroyThread },
1134
+ { "WaitThread", glfw_WaitThread },
1135
+ { "GetThreadID", glfw_GetThreadID },
1136
+ { "CreateMutex", glfw_CreateMutex },
1137
+ { "DestroyMutex", glfw_DestroyMutex },
1138
+ { "LockMutex", glfw_LockMutex },
1139
+ { "UnlockMutex", glfw_UnlockMutex },
1140
+ { "CreateCond", glfw_CreateCond },
1141
+ { "DestroyCond", glfw_DestroyCond },
1142
+ { "WaitCond", glfw_WaitCond },
1143
+ { "SignalCond", glfw_SignalCond },
1144
+ { "BroadcastCond", glfw_BroadcastCond },
1145
+ { "GetNumberOfProcessors", glfw_GetNumberOfProcessors },
1146
+ { "Enable", glfw_Enable },
1147
+ { "Disable", glfw_Disable },
1148
+ { "ReadImage", glfw_ReadImage },
1149
+ { "FreeImage", glfw_FreeImage },
1150
+ { "LoadTexture2D", glfw_LoadTexture2D },
1151
+ { "SetWindowSizeCallback", glfw_SetWindowSizeCallback },
1152
+ { "SetWindowCloseCallback", glfw_SetWindowCloseCallback },
1153
+ { "SetWindowRefreshCallback", glfw_SetWindowRefreshCallback },
1154
+ { "SetMouseButtonCallback", glfw_SetMouseButtonCallback },
1155
+ { "SetMousePosCallback", glfw_SetMousePosCallback },
1156
+ { "SetMouseWheelCallback", glfw_SetMouseWheelCallback },
1157
+ { "SetKeyCallback", glfw_SetKeyCallback },
1158
+ { "SetCharCallback", glfw_SetCharCallback },
1159
+ { NULL, NULL }
1160
+ };
1161
+
1162
+
1163
+
1164
+ int luaopen_glfw( lua_State *L )
1165
+ {
1166
+ // Store GLFW functions in "glfw" table
1167
+ luaL_openlib( L, "glfw", glfwlib, 0 );
1168
+
1169
+ // Store GLFW constants in "glfw" table
1170
+ lua_pushstring( L, "glfw" );
1171
+ lua_gettable( L, LUA_GLOBALSINDEX );
1172
+ addConstants( L, glfw_constants );
1173
+ lua_settop( L, 0 );
1174
+
1175
+ // Remember Lua state for callback functions
1176
+ callback_lua_state = L;
1177
+
1178
+ return 0;
1179
+ }