Mercurial > almixer_isolated
annotate Isolated/luaal/luaal.c @ 64:aace3301c8d1
Fixed misspelled function name in _WIN32 section 'Internal_PlatformPlatformGetThreadID' (looks like search & replace bug). Thanks to Johnson Lin reporting this issue!
Johnson Lin < arch . jslin - at - gmail . com >
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Tue, 19 Jun 2012 00:33:00 -0700 |
parents | d7da72703681 |
children |
rev | line source |
---|---|
38 | 1 /* |
2 LuaOpenAL | |
3 Copyright (C) 2010 Eric Wing <ewing . public @ playcontrol.net> | |
4 | |
5 Permission is hereby granted, free of charge, to any person obtaining a copy | |
6 of this software and associated documentation files (the "Software"), to deal | |
7 in the Software without restriction, including without limitation the rights | |
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
9 copies of the Software, and to permit persons to whom the Software is | |
10 furnished to do so, subject to the following conditions: | |
11 | |
12 The above copyright notice and this permission notice shall be included in | |
13 all copies or substantial portions of the Software. | |
14 | |
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
21 THE SOFTWARE. | |
22 | |
23 */ | |
24 #include "al.h" | |
25 /* #include "alc.h" */ | |
26 | |
27 #include "lua.h" | |
28 #include "lauxlib.h" | |
29 | |
30 #define LUAAL_VERSION "1.1" | |
31 | |
32 typedef struct luaopenal_Enum | |
33 { | |
34 const char* stringName; | |
35 ALenum alValue; | |
36 } luaopenal_Enum; | |
37 | |
38 | |
39 void luaopenal_initenum(lua_State* lua_state, const luaopenal_Enum* al_enums) | |
40 { | |
41 for( ; al_enums->stringName; al_enums++) | |
42 { | |
43 lua_pushstring(lua_state, al_enums->stringName); | |
44 lua_pushinteger(lua_state, al_enums->alValue); | |
45 lua_settable(lua_state, -3); | |
46 } | |
47 } | |
48 | |
49 | |
50 static const luaopenal_Enum s_luaALEnum[] = { | |
51 { "INVALID", AL_INVALID }, | |
52 { "NONE", AL_NONE }, | |
53 { "FALSE", AL_FALSE }, | |
54 { "TRUE", AL_TRUE }, | |
55 { "SOURCE_RELATIVE", AL_SOURCE_RELATIVE }, | |
56 { "CONE_INNER_ANGLE", AL_CONE_INNER_ANGLE }, | |
57 { "CONE_OUTER_ANGLE", AL_CONE_OUTER_ANGLE }, | |
58 { "PITCH", AL_PITCH }, | |
59 { "POSITION", AL_POSITION }, | |
60 { "DIRECTION", AL_DIRECTION }, | |
61 { "VELOCITY", AL_VELOCITY }, | |
62 { "LOOPING", AL_LOOPING }, | |
63 { "BUFFER", AL_BUFFER }, | |
64 { "GAIN", AL_GAIN }, | |
65 { "MIN_GAIN", AL_MIN_GAIN }, | |
66 { "MAX_GAIN", AL_MAX_GAIN }, | |
67 { "ORIENTATION", AL_ORIENTATION }, | |
68 /* { "CHANNEL_MASK", AL_CHANNEL_MASK }, */ | |
69 { "SOURCE_STATE", AL_SOURCE_STATE }, | |
70 { "INITIAL", AL_INITIAL }, | |
71 { "PLAYING", AL_PLAYING }, | |
72 { "PAUSED", AL_PAUSED }, | |
73 { "STOPPED", AL_STOPPED }, | |
74 { "BUFFERS_QUEUED", AL_BUFFERS_QUEUED }, | |
75 { "BUFFERS_PROCESSED", AL_BUFFERS_PROCESSED }, | |
76 { "SEC_OFFSET", AL_SEC_OFFSET }, | |
77 { "SAMPLE_OFFSET", AL_SAMPLE_OFFSET }, | |
78 { "BYTE_OFFSET", AL_BYTE_OFFSET }, | |
79 { "SOURCE_TYPE", AL_SOURCE_TYPE }, | |
80 { "STATIC", AL_STATIC }, | |
81 { "STREAMING", AL_STREAMING }, | |
82 { "UNDETERMINED", AL_UNDETERMINED }, | |
83 { "FORMAT_MONO8", AL_FORMAT_MONO8 }, | |
84 { "FORMAT_MONO16", AL_FORMAT_MONO16 }, | |
85 { "FORMAT_STEREO8", AL_FORMAT_STEREO8 }, | |
86 { "FORMAT_STEREO16", AL_FORMAT_STEREO16 }, | |
87 { "REFERENCE_DISTANCE", AL_REFERENCE_DISTANCE }, | |
88 { "ROLLOFF_FACTOR", AL_ROLLOFF_FACTOR }, | |
89 { "CONE_OUTER_GAIN", AL_CONE_OUTER_GAIN }, | |
90 { "MAX_DISTANCE", AL_MAX_DISTANCE }, | |
91 { "FREQUENCY", AL_FREQUENCY }, | |
92 { "BITS", AL_BITS }, | |
93 { "CHANNELS", AL_CHANNELS }, | |
94 { "SIZE", AL_SIZE }, | |
95 /* | |
96 { "UNUSED", AL_UNUSED }, | |
97 { "PENDING", AL_PENDING }, | |
98 { "PROCESSED", AL_PROCESSED }, | |
99 */ | |
100 { "NO_ERROR", AL_NO_ERROR }, | |
101 { "INVALID_NAME", AL_INVALID_NAME }, | |
102 { "ILLEGAL_ENUM", AL_ILLEGAL_ENUM }, | |
103 { "INVALID_VALUE", AL_INVALID_VALUE }, | |
104 { "ILLEGAL_COMMAND", AL_ILLEGAL_COMMAND }, | |
105 { "INVALID_OPERATION", AL_INVALID_OPERATION }, | |
106 { "OUT_OF_MEMORY", AL_OUT_OF_MEMORY }, | |
107 { "VENDOR", AL_VENDOR }, | |
108 { "VERSION", AL_VERSION }, | |
109 { "RENDERER", AL_RENDERER }, | |
110 { "EXTENSIONS", AL_EXTENSIONS }, | |
111 { "DOPPLER_FACTOR", AL_DOPPLER_FACTOR }, | |
112 { "DOPPLER_VELOCITY", AL_DOPPLER_VELOCITY }, | |
113 { "SPEED_OF_SOUND", AL_SPEED_OF_SOUND }, | |
114 { "DISTANCE_MODEL", AL_DISTANCE_MODEL }, | |
115 { "INVERSE_DISTANCE", AL_INVERSE_DISTANCE }, | |
116 { "INVERSE_DISTANCE_CLAMPED", AL_INVERSE_DISTANCE_CLAMPED }, | |
117 { "LINEAR_DISTANCE", AL_LINEAR_DISTANCE }, | |
118 { "LINEAR_DISTANCE_CLAMPED", AL_LINEAR_DISTANCE_CLAMPED }, | |
119 { "EXPONENT_DISTANCE", AL_EXPONENT_DISTANCE }, | |
120 { "EXPONENT_DISTANCE_CLAMPED", AL_EXPONENT_DISTANCE_CLAMPED }, | |
121 { 0, 0 } | |
122 }; | |
123 | |
124 | |
125 #define LUAOPENAL_BOOL_TYPE 1 | |
126 #define LUAOPENAL_INT_TYPE 2 | |
127 #define LUAOPENAL_FLOAT_TYPE 3 | |
128 | |
129 | |
130 #define LUAOPENAL_INT_3_TYPE 4 | |
131 #define LUAOPENAL_FLOAT_3_TYPE 5 | |
132 #define LUAOPENAL_FLOAT_6_TYPE 6 | |
133 #define LUAOPENAL_STRING_TYPE 7 | |
134 | |
135 | |
136 static int lua_getTypeForEnum(ALenum enum_parameter) | |
137 { | |
138 switch(enum_parameter) | |
139 { | |
140 case AL_SOURCE_RELATIVE: | |
141 case AL_LOOPING: | |
142 { | |
143 return LUAOPENAL_BOOL_TYPE; | |
144 break; | |
145 } | |
146 | |
46
d7da72703681
Added AL_SOURCE_STATE to luaal
Eric Wing <ewing@anscamobile.com>
parents:
38
diff
changeset
|
147 case AL_SOURCE_STATE: |
38 | 148 case AL_SOURCE_TYPE: |
149 case AL_BUFFER: | |
150 case AL_BUFFERS_QUEUED: | |
151 case AL_BUFFERS_PROCESSED: | |
152 { | |
153 return LUAOPENAL_INT_TYPE; | |
154 break; | |
155 } | |
156 case AL_GAIN: | |
157 case AL_MIN_GAIN: | |
158 case AL_MAX_GAIN: | |
159 case AL_REFERENCE_DISTANCE: /* could be integer */ | |
160 case AL_ROLLOFF_FACTOR: /* could be integer */ | |
161 case AL_MAX_DISTANCE: /* could be integer */ | |
162 case AL_PITCH: | |
163 case AL_CONE_INNER_ANGLE: /* could be integer */ | |
164 case AL_CONE_OUTER_ANGLE: /* could be integer */ | |
165 case AL_CONE_OUTER_GAIN: /* interesting...only f,fv according to spec */ | |
166 case AL_SAMPLE_OFFSET: /* could be integer */ | |
167 case AL_BYTE_OFFSET: /* could be integer */ | |
168 case AL_SEC_OFFSET: /* could be integer */ | |
169 | |
170 case AL_DOPPLER_FACTOR: | |
171 case AL_DOPPLER_VELOCITY: | |
172 case AL_SPEED_OF_SOUND: | |
173 { | |
174 return LUAOPENAL_FLOAT_TYPE; | |
175 break; | |
176 } | |
177 | |
178 case AL_POSITION: /* could be integer */ | |
179 case AL_VELOCITY: /* could be integer */ | |
180 case AL_DIRECTION: /* could be integer */ | |
181 { | |
182 return LUAOPENAL_FLOAT_3_TYPE; | |
183 break; | |
184 } | |
185 | |
186 case AL_ORIENTATION: /* could be integer */ | |
187 { | |
188 return LUAOPENAL_FLOAT_6_TYPE; | |
189 break; | |
190 } | |
191 | |
192 case AL_NO_ERROR: | |
193 case AL_INVALID_NAME: | |
194 case AL_ILLEGAL_ENUM: | |
195 /* case AL_INVALID_ENUM: */ /* same as AL_ILLEGAL_ENUM */ | |
196 case AL_INVALID_VALUE: | |
197 case AL_ILLEGAL_COMMAND: | |
198 /* case AL_INVALID_OPERATION: */ /* same as AL_ILLEGAL_COMMAND */ | |
199 case AL_OUT_OF_MEMORY: | |
200 case AL_VENDOR: | |
201 case AL_VERSION: | |
202 case AL_RENDERER: | |
203 case AL_EXTENSIONS: | |
204 { | |
205 return LUAOPENAL_STRING_TYPE; | |
206 break; | |
207 } | |
208 | |
209 } | |
210 return 0; | |
211 } | |
212 | |
213 static int lua_alEnable(lua_State* lua_state) | |
214 { | |
215 ALenum enum_parameter; | |
216 enum_parameter = lua_tointeger(lua_state, 1); | |
217 alEnable(enum_parameter); | |
218 return 0; | |
219 } | |
220 | |
221 static int lua_alDisable(lua_State* lua_state) | |
222 { | |
223 ALenum enum_parameter; | |
224 enum_parameter = lua_tointeger(lua_state, 1); | |
225 alDisable(enum_parameter); | |
226 return 0; | |
227 } | |
228 | |
229 static int lua_alIsEnabled(lua_State* lua_state) | |
230 { | |
231 ALenum enum_parameter; | |
232 ALboolean ret_val; | |
233 enum_parameter = lua_tointeger(lua_state, 1); | |
234 ret_val = alIsEnabled(enum_parameter); | |
235 lua_pushboolean(lua_state, ret_val); | |
236 return 1; | |
237 } | |
238 | |
239 static int lua_alGetError(lua_State* lua_state) | |
240 { | |
241 ALenum ret_val; | |
242 ret_val = alGetError(); | |
243 lua_pushinteger(lua_state, ret_val); | |
244 return 1; | |
245 } | |
246 | |
247 static int lua_alIsExtensionPresent(lua_State* lua_state) | |
248 { | |
249 const ALchar* string_name; | |
250 ALboolean ret_val; | |
251 string_name = lua_tostring(lua_state, 1); | |
252 ret_val = alIsExtensionPresent(string_name); | |
253 lua_pushboolean(lua_state, ret_val); | |
254 return 1; | |
255 } | |
256 | |
257 /* TODO: alGetProcAddress */ | |
258 | |
259 static int lua_alGetEnumValue(lua_State* lua_state) | |
260 { | |
261 const ALchar* string_name; | |
262 ALenum ret_val; | |
263 string_name = lua_tostring(lua_state, 1); | |
264 ret_val = alGetEnumValue(string_name); | |
265 lua_pushinteger(lua_state, ret_val); | |
266 return 1; | |
267 } | |
268 | |
269 | |
270 | |
271 | |
272 static int lua_alGetListener(lua_State* lua_state) | |
273 { | |
274 ALenum enum_parameter; | |
275 int openal_primitive_type; | |
276 | |
277 enum_parameter = lua_tointeger(lua_state, 1); | |
278 | |
279 openal_primitive_type = lua_getTypeForEnum(enum_parameter); | |
280 | |
281 switch(openal_primitive_type) | |
282 { | |
283 case LUAOPENAL_BOOL_TYPE: | |
284 { | |
285 ALint ret_val; | |
286 alGetListeneri(enum_parameter, &ret_val); | |
287 lua_pushboolean(lua_state, ret_val); | |
288 return 1; | |
289 break; | |
290 } | |
291 case LUAOPENAL_INT_TYPE: | |
292 { | |
293 ALint ret_val; | |
294 alGetListeneri(enum_parameter, &ret_val); | |
295 lua_pushinteger(lua_state, ret_val); | |
296 return 1; | |
297 break; | |
298 } | |
299 case LUAOPENAL_FLOAT_TYPE: | |
300 { | |
301 ALfloat ret_val; | |
302 alGetListenerf(enum_parameter, &ret_val); | |
303 lua_pushnumber(lua_state, ret_val); | |
304 return 1; | |
305 break; | |
306 } | |
307 case LUAOPENAL_INT_3_TYPE: | |
308 { | |
309 ALint ret_val[3]; | |
310 alGetListeneriv(enum_parameter, ret_val); | |
311 lua_pushinteger(lua_state, ret_val[0]); | |
312 lua_pushinteger(lua_state, ret_val[1]); | |
313 lua_pushinteger(lua_state, ret_val[2]); | |
314 return 3; | |
315 break; | |
316 } | |
317 case LUAOPENAL_FLOAT_3_TYPE: | |
318 { | |
319 ALfloat ret_val[3]; | |
320 alGetListenerfv(enum_parameter, ret_val); | |
321 lua_pushnumber(lua_state, ret_val[0]); | |
322 lua_pushnumber(lua_state, ret_val[1]); | |
323 lua_pushnumber(lua_state, ret_val[2]); | |
324 return 3; | |
325 break; | |
326 } | |
327 case LUAOPENAL_FLOAT_6_TYPE: | |
328 { | |
329 ALfloat ret_val[6]; | |
330 alGetListenerfv(enum_parameter, ret_val); | |
331 lua_pushnumber(lua_state, ret_val[0]); | |
332 lua_pushnumber(lua_state, ret_val[1]); | |
333 lua_pushnumber(lua_state, ret_val[2]); | |
334 lua_pushnumber(lua_state, ret_val[3]); | |
335 lua_pushnumber(lua_state, ret_val[4]); | |
336 lua_pushnumber(lua_state, ret_val[5]); | |
337 return 6; | |
338 break; | |
339 } | |
340 default: | |
341 { | |
342 /* TODO: Figure out how to handle OpenAL extensions. */ | |
343 luaL_error(lua_state, "Unhandled parameter type for alGetSource*"); | |
344 } | |
345 } | |
346 return 0; | |
347 } | |
348 | |
349 static int lua_alListener(lua_State* lua_state) | |
350 { | |
351 ALenum enum_parameter; | |
352 int openal_primitive_type; | |
353 | |
354 enum_parameter = lua_tointeger(lua_state, 1); | |
355 | |
356 | |
357 openal_primitive_type = lua_getTypeForEnum(enum_parameter); | |
358 | |
359 switch(openal_primitive_type) | |
360 { | |
361 case LUAOPENAL_BOOL_TYPE: | |
362 case LUAOPENAL_INT_TYPE: | |
363 { | |
364 alListeneri(enum_parameter, lua_tointeger(lua_state, 2)); | |
365 break; | |
366 } | |
367 case LUAOPENAL_FLOAT_TYPE: | |
368 { | |
369 alListenerf(enum_parameter, lua_tonumber(lua_state, 2)); | |
370 break; | |
371 } | |
372 case LUAOPENAL_INT_3_TYPE: | |
373 { | |
374 alListener3i(enum_parameter, lua_tointeger(lua_state, 2), lua_tointeger(lua_state, 3), lua_tointeger(lua_state, 4)); | |
375 break; | |
376 } | |
377 case LUAOPENAL_FLOAT_3_TYPE: | |
378 { | |
379 alListener3f(enum_parameter, lua_tonumber(lua_state, 2), lua_tonumber(lua_state, 3), lua_tonumber(lua_state, 4)); | |
380 break; | |
381 } | |
382 case LUAOPENAL_FLOAT_6_TYPE: | |
383 { | |
384 ALfloat val_array[6] = | |
385 { | |
386 lua_tonumber(lua_state, 2), | |
387 lua_tonumber(lua_state, 3), | |
388 lua_tonumber(lua_state, 4), | |
389 lua_tonumber(lua_state, 5), | |
390 lua_tonumber(lua_state, 6), | |
391 lua_tonumber(lua_state, 7) | |
392 }; | |
393 | |
394 alListenerfv(enum_parameter, val_array); | |
395 break; | |
396 } | |
397 default: | |
398 { | |
399 /* TODO: Figure out how to handle OpenAL extensions. */ | |
400 luaL_error(lua_state, "Unhandled parameter type for alSource*"); | |
401 } | |
402 } | |
403 return 0; | |
404 } | |
405 | |
406 | |
407 | |
408 | |
409 static int lua_alGetSource(lua_State* lua_state) | |
410 { | |
411 ALuint source_id; | |
412 ALenum enum_parameter; | |
413 int openal_primitive_type; | |
414 | |
415 source_id = lua_tointeger(lua_state, 1); | |
416 enum_parameter = lua_tointeger(lua_state, 2); | |
417 | |
418 openal_primitive_type = lua_getTypeForEnum(enum_parameter); | |
419 | |
420 switch(openal_primitive_type) | |
421 { | |
422 case LUAOPENAL_BOOL_TYPE: | |
423 { | |
424 ALint ret_val; | |
425 alGetSourcei(source_id, enum_parameter, &ret_val); | |
426 lua_pushboolean(lua_state, ret_val); | |
427 return 1; | |
428 break; | |
429 } | |
430 case LUAOPENAL_INT_TYPE: | |
431 { | |
432 ALint ret_val; | |
433 alGetSourcei(source_id, enum_parameter, &ret_val); | |
434 lua_pushinteger(lua_state, ret_val); | |
435 return 1; | |
436 break; | |
437 } | |
438 case LUAOPENAL_FLOAT_TYPE: | |
439 { | |
440 ALfloat ret_val; | |
441 alGetSourcef(source_id, enum_parameter, &ret_val); | |
442 lua_pushnumber(lua_state, ret_val); | |
443 return 1; | |
444 break; | |
445 } | |
446 case LUAOPENAL_INT_3_TYPE: | |
447 { | |
448 ALint ret_val[3]; | |
449 alGetSourceiv(source_id, enum_parameter, ret_val); | |
450 lua_pushinteger(lua_state, ret_val[0]); | |
451 lua_pushinteger(lua_state, ret_val[1]); | |
452 lua_pushinteger(lua_state, ret_val[2]); | |
453 return 3; | |
454 break; | |
455 } | |
456 case LUAOPENAL_FLOAT_3_TYPE: | |
457 { | |
458 ALfloat ret_val[3]; | |
459 alGetSourcefv(source_id, enum_parameter, ret_val); | |
460 lua_pushnumber(lua_state, ret_val[0]); | |
461 lua_pushnumber(lua_state, ret_val[1]); | |
462 lua_pushnumber(lua_state, ret_val[2]); | |
463 return 3; | |
464 break; | |
465 } | |
466 default: | |
467 { | |
468 /* TODO: Figure out how to handle OpenAL extensions. */ | |
469 luaL_error(lua_state, "Unhandled parameter type for alGetSource*"); | |
470 } | |
471 } | |
472 return 0; | |
473 } | |
474 | |
475 | |
476 static int lua_alSource(lua_State* lua_state) | |
477 { | |
478 ALuint source_id; | |
479 ALenum enum_parameter; | |
480 int openal_primitive_type; | |
481 | |
482 source_id = lua_tointeger(lua_state, 1); | |
483 enum_parameter = lua_tointeger(lua_state, 2); | |
484 | |
485 openal_primitive_type = lua_getTypeForEnum(enum_parameter); | |
486 | |
487 switch(openal_primitive_type) | |
488 { | |
489 case LUAOPENAL_BOOL_TYPE: | |
490 case LUAOPENAL_INT_TYPE: | |
491 { | |
492 alSourcei(source_id, enum_parameter, lua_tointeger(lua_state, 3)); | |
493 break; | |
494 } | |
495 case LUAOPENAL_FLOAT_TYPE: | |
496 { | |
497 alSourcef(source_id, enum_parameter, lua_tonumber(lua_state, 3)); | |
498 break; | |
499 } | |
500 case LUAOPENAL_INT_3_TYPE: | |
501 { | |
502 alSource3i(source_id, enum_parameter, lua_tointeger(lua_state, 3), lua_tointeger(lua_state, 4), lua_tointeger(lua_state, 5)); | |
503 break; | |
504 } | |
505 case LUAOPENAL_FLOAT_3_TYPE: | |
506 { | |
507 alSource3f(source_id, enum_parameter, lua_tonumber(lua_state, 3), lua_tonumber(lua_state, 4), lua_tonumber(lua_state, 5)); | |
508 break; | |
509 } | |
510 default: | |
511 { | |
512 /* TODO: Figure out how to handle OpenAL extensions. */ | |
513 luaL_error(lua_state, "Unhandled parameter type for alSource*"); | |
514 } | |
515 } | |
516 return 0; | |
517 } | |
518 | |
519 | |
520 static int lua_alDopplerFactor(lua_State* lua_state) | |
521 { | |
522 ALfloat the_value; | |
523 the_value = lua_tonumber(lua_state, 1); | |
524 alDopplerFactor(the_value); | |
525 return 0; | |
526 } | |
527 | |
528 static int lua_alDopplerVelocity(lua_State* lua_state) | |
529 { | |
530 ALfloat the_value; | |
531 the_value = lua_tonumber(lua_state, 1); | |
532 alDopplerVelocity(the_value); | |
533 return 0; | |
534 } | |
535 | |
536 static int lua_alSpeedOfSound(lua_State* lua_state) | |
537 { | |
538 ALfloat the_value; | |
539 the_value = lua_tonumber(lua_state, 1); | |
540 alSpeedOfSound(the_value); | |
541 return 0; | |
542 } | |
543 | |
544 static int lua_alDistanceModel(lua_State* lua_state) | |
545 { | |
546 ALenum enum_parameter; | |
547 enum_parameter = lua_tointeger(lua_state, 1); | |
548 alDistanceModel(enum_parameter); | |
549 return 0; | |
550 } | |
551 | |
552 static int lua_alGet(lua_State* lua_state) | |
553 { | |
554 ALenum enum_parameter; | |
555 int openal_primitive_type; | |
556 | |
557 enum_parameter = lua_tointeger(lua_state, 1); | |
558 | |
559 openal_primitive_type = lua_getTypeForEnum(enum_parameter); | |
560 | |
561 switch(openal_primitive_type) | |
562 { | |
563 case LUAOPENAL_BOOL_TYPE: | |
564 { | |
565 ALboolean ret_val; | |
566 ret_val = alGetBoolean(enum_parameter); | |
567 lua_pushboolean(lua_state, ret_val); | |
568 return 1; | |
569 break; | |
570 } | |
571 case LUAOPENAL_INT_TYPE: | |
572 { | |
573 ALint ret_val; | |
574 ret_val = alGetInteger(enum_parameter); | |
575 lua_pushinteger(lua_state, ret_val); | |
576 return 1; | |
577 break; | |
578 } | |
579 case LUAOPENAL_FLOAT_TYPE: | |
580 { | |
581 ALfloat ret_val; | |
582 ret_val = alGetFloat(enum_parameter); | |
583 lua_pushnumber(lua_state, ret_val); | |
584 return 1; | |
585 break; | |
586 } | |
587 case LUAOPENAL_INT_3_TYPE: | |
588 { | |
589 ALint ret_val[3]; | |
590 alGetIntegerv(enum_parameter, ret_val); | |
591 lua_pushinteger(lua_state, ret_val[0]); | |
592 lua_pushinteger(lua_state, ret_val[1]); | |
593 lua_pushinteger(lua_state, ret_val[2]); | |
594 return 3; | |
595 break; | |
596 } | |
597 case LUAOPENAL_FLOAT_3_TYPE: | |
598 { | |
599 ALfloat ret_val[3]; | |
600 alGetFloatv(enum_parameter, ret_val); | |
601 lua_pushnumber(lua_state, ret_val[0]); | |
602 lua_pushnumber(lua_state, ret_val[1]); | |
603 lua_pushnumber(lua_state, ret_val[2]); | |
604 return 3; | |
605 break; | |
606 } | |
607 case LUAOPENAL_FLOAT_6_TYPE: | |
608 { | |
609 ALfloat ret_val[6]; | |
610 alGetFloatv(enum_parameter, ret_val); | |
611 lua_pushnumber(lua_state, ret_val[0]); | |
612 lua_pushnumber(lua_state, ret_val[1]); | |
613 lua_pushnumber(lua_state, ret_val[2]); | |
614 lua_pushnumber(lua_state, ret_val[3]); | |
615 lua_pushnumber(lua_state, ret_val[4]); | |
616 lua_pushnumber(lua_state, ret_val[5]); | |
617 return 6; | |
618 break; | |
619 } | |
620 case LUAOPENAL_STRING_TYPE: | |
621 { | |
622 const ALchar* ret_val; | |
623 ret_val = alGetString(enum_parameter); | |
624 lua_pushstring(lua_state, ret_val); | |
625 return 1; | |
626 break; | |
627 } | |
628 default: | |
629 { | |
630 /* TODO: Figure out how to handle OpenAL extensions. */ | |
631 luaL_error(lua_state, "Unhandled parameter type for alGetSource*"); | |
632 } | |
633 } | |
634 return 0; | |
635 } | |
636 | |
637 static const luaL_reg luaALFuncs[] = | |
638 { | |
639 { "Enable", lua_alEnable }, | |
640 { "Disable", lua_alDisable }, | |
641 { "IsEnabled", lua_alIsEnabled }, | |
642 { "Get", lua_alGet }, | |
643 { "GetError", lua_alGetError }, | |
644 { "IsExtensionPresent", lua_alIsExtensionPresent }, | |
645 { "GetEnumValue", lua_alGetEnumValue }, | |
646 { "Listener", lua_alListener }, | |
647 { "GetListener", lua_alGetListener }, | |
648 { "Source", lua_alSource }, | |
649 { "GetSource", lua_alGetSource }, | |
650 { "DopplerFactor", lua_alDopplerFactor }, | |
651 { "DopplerVelocity", lua_alDopplerVelocity }, | |
652 { "SpeedOfSound", lua_alSpeedOfSound }, | |
653 { "DistanceModel", lua_alDistanceModel }, | |
654 { "DopplerVelocity", lua_alDopplerVelocity }, | |
655 {NULL, NULL} | |
656 }; | |
657 | |
658 | |
659 int luaopen_luaal(lua_State *L) | |
660 { | |
661 luaL_register(L, "al", luaALFuncs); | |
662 | |
663 luaopenal_initenum(L, s_luaALEnum); | |
664 | |
665 lua_pushstring(L, "_VERSION"); | |
666 lua_pushstring(L, LUAAL_VERSION); | |
667 lua_settable(L,-3); | |
668 | |
669 return 1; | |
670 } | |
671 | |
672 |