Repository navigation
Expand file tree
/
Copy pathlegato.c
More file actions
6020 lines (5158 loc) · 197 KB
/
Copy pathlegato.c
File metadata and controls
6020 lines (5158 loc) · 197 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
================================================================================
Legato - a Lua based gaming framework
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
This software was written by Sebastian Steinhauer <s.steinhauer@yahoo.de>
Chanelog:
---------
2014-02-13 - 0.3.6
* added path methods
2013-12-29 - 0.3.5
* get peer round trip time
* implemented get_parent_bitmap
* fixed some type conversions
2013-12-29 - 0.3.4
* fixed legato.al.copy_transform
* show dialog box for MacOS X
* added support for 'x', '?' in pack/unpack
* add save_bitmap
* implemented grab_font_from_bitmap
* add service as method for hosts
* fixed key BACKSPACE
2013-12-05 - 0.3.3
* fixed fs.set_write_dir
* fixed mouse_button_up event
* added missing bitmap draw methods
2013-11-29 - 0.3.2
* fixed crash when using al.get_default_mixer()
* add version info to Windows-Messagebox
2013-11-25 - 0.3.1
* added core.get_os_type() (relies on the Allegro5 defines)
2013-11-22 - 0.3.0
* implemented joystick routines
* implemented joystick events
* changed style of event source registration/unregistration
* added keycode enums
* added number map
2013-11-20 - 0.2.1
* added licenses.txt (use xxd -i to create licenses.h)
* new function to get all licenses
* push now right display/timer object on events
* added Mersenne Twister pseudo random number generator
* try to mount executable file to / on startup
2013-11-14 - 0.2.0
* added zlib compression/decompression stuff
* crc32/adler32 routines (zlib as well)
* add new UTF8 string split (split into codepoints)
* new binary packing/unpacking routines
* new base64 encoder/decoder
* new legato.rand module
* added Linear congruential generator
2013-11-04 - 0.1.1
Moved some functions to legato.core (because they don't belong to
legato.al). Implemented ENet support. Should be working now. Added mouse
cursor functions.
2013-10-17 - 0.1.0
This is the first version. Almost every Allegro 5 and PhysFS stuff is
implemented right now. enet (robust fast UDP networking) is non-functional
right now.
================================================================================
*/
/*
================================================================================
INCLUDES
================================================================================
*/
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include <physfs.h>
#include <zlib.h>
#include <enet/enet.h>
#include <allegro5/allegro.h>
#include <allegro5/allegro_physfs.h>
#include <allegro5/allegro_image.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_audio.h>
#include <allegro5/allegro_acodec.h>
#include <allegro5/allegro_color.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#ifdef ALLEGRO_WINDOWS
#include <allegro5/allegro_direct3d.h>
#include <allegro5/allegro_native_dialog.h>
#define LEGATO_DIRECT3D ALLEGRO_DIRECT3D
#else
#define LEGATO_DIRECT3D 0
#endif /* ALLEGRO_WINDOWS */
#include "licenses.h" /* include license text */
/* #define DEBUG_OBJECT_LIFE */ /* activate to see object creation/destruction */
#define NOT_IMPLEMENTED_MACRO luaL_error(L, "Error: not implemented yet!"); return 0;
#define LEGATO_VERSION_MAJOR 0
#define LEGATO_VERSION_MINOR 3
#define LEGATO_VERSION_PATCH 6
#define LEGATO_LITTLE_ENDIAN 0
#define LEGATO_BIG_ENDIAN 1
#ifdef ALLEGRO_LITTLE_ENDIAN
#define LEGATO_NATIVE_ENDIAN LEGATO_LITTLE_ENDIAN
#else
#define LEGATO_NATIVE_ENDIAN LEGATO_BIG_ENDIAN
#endif /* ALLEGRO_LITTLE_ENDIAN */
#define ZLIB_COMPRESSION_BUFFER_SIZE (1024 * 16) /* compress is 16kb chunks */
/*
================================================================================
OBJECT NAMES
================================================================================
*/
#define LEGATO_CONFIG "legato_config"
#define LEGATO_DISPLAY "legato_display"
#define LEGATO_COLOR "legato_color"
#define LEGATO_BITMAP "legato_bitmap"
#define LEGATO_EVENT_QUEUE "legato_event_queue"
#define LEGATO_KEYBOARD_STATE "legato_keyboard_state"
#define LEGATO_MOUSE_STATE "legato_mouse_state"
#define LEGATO_MOUSE_CURSOR "legato_mouse_cursor"
#define LEGATO_PATH "legato_path"
#define LEGATO_STATE "legato_state"
#define LEGATO_TIMER "legato_timer"
#define LEGATO_TRANSFORM "legato_transform"
#define LEGATO_JOYSTICK "legato_joystick"
#define LEGATO_JOYSTICK_STATE "legato_joystick_state"
#define LEGATO_VOICE "legato_voice"
#define LEGATO_MIXER "legato_mixer"
#define LEGATO_AUDIO_SAMPLE "legato_audio_sample"
#define LEGATO_SAMPLE_ID "legato_sample_id"
#define LEGATO_SAMPLE_INSTANCE "legato_sample_instance"
#define LEGATO_AUDIO_STREAM "legato_audio_stream"
#define LEGATO_FONT "legato_font"
#define LEGATO_FILE "legato_file"
#define LEGATO_ADDRESS "legato_address"
#define LEGATO_HOST "legato_host"
#define LEGATO_PEER "legato_peer"
#define LEGATO_RAND_LCG "legato_rand_lcg"
#define LEGATO_RAND_MT "legato_rand_mt"
#define LEGATO_NUMBER_MAP "legato_number_map"
/*
================================================================================
STRUCTURES
================================================================================
*/
typedef struct mapping_t {
const char *name;
const int value;
} mapping_t;
typedef struct object_t {
void *ptr;
const char *name;
int destroy;
int dependency_ref;
} object_t;
typedef struct rand_lgc_t {
uint32_t X, a, c;
} rand_lcg_t;
typedef struct rand_mt_t {
unsigned long mt[624];
int mti;
} rand_mt_t;
typedef struct number_map_t {
int width, height;
lua_Number cells[1];
} number_map_t;
/*
================================================================================
PROTOTYPES
================================================================================
*/
static ALLEGRO_CONFIG *to_config( lua_State *L, const int idx );
static ALLEGRO_DISPLAY *to_display( lua_State *L, const int idx );
static ALLEGRO_COLOR to_color( lua_State *L, const int idx );
static ALLEGRO_BITMAP *to_bitmap( lua_State *L, const int idx );
static ALLEGRO_EVENT_QUEUE *to_event_queue( lua_State *L, const int idx );
static ALLEGRO_KEYBOARD_STATE *to_keyboard_state( lua_State *L, const int idx );
static ALLEGRO_MOUSE_STATE *to_mouse_state( lua_State *L, const int idx );
static ALLEGRO_MOUSE_CURSOR *to_mouse_cursor( lua_State *L, const int idx );
static ALLEGRO_PATH *to_path( lua_State *L, const int idx );
static ALLEGRO_STATE *to_state( lua_State *L, const int idx );
static ALLEGRO_TIMER *to_timer( lua_State *L, const int idx );
static ALLEGRO_TRANSFORM *to_transform( lua_State *L, const int idx );
static ALLEGRO_JOYSTICK *to_joystick( lua_State *L, const int idx );
static ALLEGRO_JOYSTICK_STATE *to_joystick_state( lua_State *L, const int idx );
static ALLEGRO_VOICE *to_voice( lua_State *L, const int idx );
static ALLEGRO_MIXER *to_mixer( lua_State *L, const int idx );
static ALLEGRO_SAMPLE *to_audio_sample( lua_State *L, const int idx );
static ALLEGRO_SAMPLE_ID *to_sample_id( lua_State *L, const int idx );
static ALLEGRO_SAMPLE_INSTANCE *to_sample_instance( lua_State *L, const int idx );
static ALLEGRO_AUDIO_STREAM *to_audio_stream( lua_State *L, const int idx );
static ALLEGRO_FONT *to_font( lua_State *L, const int idx );
static PHYSFS_File *to_file( lua_State *L, const int idx );
static ENetAddress *to_address( lua_State *L, const int idx );
static ENetHost *to_host( lua_State *L, const int idx );
static ENetPeer *to_peer( lua_State *L, const int idx );
static rand_lcg_t *to_rand_lcg( lua_State *L, const int idx );
static rand_mt_t *to_rand_mt( lua_State *L, const int idx );
static number_map_t *to_number_map( lua_State *L, const int idx );
/*
================================================================================
ENUMS
================================================================================
*/
static const mapping_t display_flag_mapping[] = {
{"windowed", ALLEGRO_WINDOWED},
{"fullscreen", ALLEGRO_FULLSCREEN},
{"fullscreen_window", ALLEGRO_FULLSCREEN_WINDOW},
{"resizable", ALLEGRO_RESIZABLE},
{"opengl", ALLEGRO_OPENGL},
{"opengl_3_0", ALLEGRO_OPENGL_3_0},
{"opengl_forward_compatible", ALLEGRO_OPENGL_FORWARD_COMPATIBLE},
{"direct3d", LEGATO_DIRECT3D},
{"frameless", ALLEGRO_FRAMELESS},
{"generate_expose_events", ALLEGRO_GENERATE_EXPOSE_EVENTS},
{"minimized", ALLEGRO_MINIMIZED},
{NULL, 0}
};
static const mapping_t display_importance_mapping[] = {
{"require", ALLEGRO_REQUIRE},
{"suggest", ALLEGRO_SUGGEST},
{"dontcare", ALLEGRO_DONTCARE},
{NULL, 0}
};
static const mapping_t display_option_mapping[] = {
{"color_size", ALLEGRO_COLOR_SIZE},
{"red_size", ALLEGRO_RED_SIZE},
{"green_size", ALLEGRO_GREEN_SIZE},
{"blue_size", ALLEGRO_BLUE_SIZE},
{"alpha_size", ALLEGRO_ALPHA_SIZE},
{"red_shift", ALLEGRO_RED_SHIFT},
{"green_shift", ALLEGRO_GREEN_SHIFT},
{"blue_shift", ALLEGRO_BLUE_SHIFT},
{"alpha_shift", ALLEGRO_ALPHA_SHIFT},
{"acc_red_size", ALLEGRO_RED_SIZE},
{"acc_green_size", ALLEGRO_GREEN_SIZE},
{"acc_blue_size", ALLEGRO_BLUE_SIZE},
{"acc_alpha_size", ALLEGRO_ALPHA_SIZE},
{"stereo", ALLEGRO_STEREO},
{"aux_buffers", ALLEGRO_AUX_BUFFERS},
{"depth_size", ALLEGRO_DEPTH_SIZE},
{"stencil_size", ALLEGRO_STENCIL_SIZE},
{"smaple_buffers", ALLEGRO_SAMPLE_BUFFERS},
{"samples", ALLEGRO_SAMPLES},
{"render_method", ALLEGRO_RENDER_METHOD},
{"float_color", ALLEGRO_FLOAT_COLOR},
{"float_depth", ALLEGRO_FLOAT_DEPTH},
{"single_buffer", ALLEGRO_SINGLE_BUFFER},
{"swap_method", ALLEGRO_SWAP_METHOD},
{"compatible_display", ALLEGRO_COMPATIBLE_DISPLAY},
{"update_display_region", ALLEGRO_UPDATE_DISPLAY_REGION},
{"vsync", ALLEGRO_VSYNC},
{"max_bitmap_size", ALLEGRO_MAX_BITMAP_SIZE},
{"support_npot_bitmap", ALLEGRO_SUPPORT_NPOT_BITMAP},
{"can_draw_into_bitmap", ALLEGRO_CAN_DRAW_INTO_BITMAP},
{"support_separate_alpha", ALLEGRO_SUPPORT_SEPARATE_ALPHA},
{NULL, 0}
};
static const mapping_t pixel_format_mapping[] = {
{"any", ALLEGRO_PIXEL_FORMAT_ANY},
{"any_no_alpha", ALLEGRO_PIXEL_FORMAT_ANY_NO_ALPHA},
{"any_with_alpha", ALLEGRO_PIXEL_FORMAT_ANY_WITH_ALPHA},
{"any_15_no_alpha", ALLEGRO_PIXEL_FORMAT_ANY_15_NO_ALPHA},
{"any_16_no_alpha", ALLEGRO_PIXEL_FORMAT_ANY_16_NO_ALPHA},
{"any_16_with_alpha", ALLEGRO_PIXEL_FORMAT_ANY_16_WITH_ALPHA},
{"any_24_no_alpha", ALLEGRO_PIXEL_FORMAT_ANY_24_NO_ALPHA},
{"any_32_no_alpha", ALLEGRO_PIXEL_FORMAT_ANY_32_NO_ALPHA},
{"any_32_with_alpha", ALLEGRO_PIXEL_FORMAT_ANY_32_WITH_ALPHA},
{"argb_8888", ALLEGRO_PIXEL_FORMAT_ARGB_8888},
{"rgba_8888", ALLEGRO_PIXEL_FORMAT_RGBA_8888},
{"argb_4444", ALLEGRO_PIXEL_FORMAT_ARGB_4444},
{"rgb_888", ALLEGRO_PIXEL_FORMAT_RGB_888},
{"rgb_565", ALLEGRO_PIXEL_FORMAT_RGB_565},
{"rgb_555", ALLEGRO_PIXEL_FORMAT_RGB_555},
{"rgba_5551", ALLEGRO_PIXEL_FORMAT_RGBA_5551},
{"argb_1555", ALLEGRO_PIXEL_FORMAT_ARGB_1555},
{"abgr_8888", ALLEGRO_PIXEL_FORMAT_ABGR_8888},
{"xbgr_8888", ALLEGRO_PIXEL_FORMAT_XBGR_8888},
{"bgr_888", ALLEGRO_PIXEL_FORMAT_BGR_888},
{"bgr_565", ALLEGRO_PIXEL_FORMAT_BGR_565},
{"bgr_555", ALLEGRO_PIXEL_FORMAT_BGR_555},
{"rgbx_8888", ALLEGRO_PIXEL_FORMAT_RGBX_8888},
{"xrgb_8888", ALLEGRO_PIXEL_FORMAT_XRGB_8888},
{"abgr_f32", ALLEGRO_PIXEL_FORMAT_ABGR_F32},
{"abgr_8888_le", ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE},
{"rgba_4444", ALLEGRO_PIXEL_FORMAT_RGBA_4444},
{NULL, 0}
};
static const mapping_t bitmap_flag_mapping[] = {
{"video_bitmap", ALLEGRO_VIDEO_BITMAP},
{"memory_bitmap", ALLEGRO_MEMORY_BITMAP},
{"keep_bitmap_format", ALLEGRO_KEEP_BITMAP_FORMAT},
{"force_locking", ALLEGRO_FORCE_LOCKING},
{"no_preserve_texture", ALLEGRO_NO_PRESERVE_TEXTURE},
{"alpha_test", ALLEGRO_ALPHA_TEST},
{"min_linear", ALLEGRO_MIN_LINEAR},
{"mag_linear", ALLEGRO_MAG_LINEAR},
{"mipmap", ALLEGRO_MIPMAP},
{"no_premultiplied_alpha", ALLEGRO_NO_PREMULTIPLIED_ALPHA},
{NULL, 0}
};
static const mapping_t draw_bitmap_mapping[] = {
{"flip_horizontal", ALLEGRO_FLIP_HORIZONTAL},
{"flip_vertical", ALLEGRO_FLIP_VERTICAL},
{NULL, 0}
};
static const mapping_t blender_op_mapping[] = {
{"add", ALLEGRO_ADD},
{"dest_minus_src", ALLEGRO_DEST_MINUS_SRC},
{"src_minus_dest", ALLEGRO_SRC_MINUS_DEST},
{NULL, 0}
};
static const mapping_t blender_arg_mapping[] = {
{"zero", ALLEGRO_ZERO},
{"one", ALLEGRO_ONE},
{"alpha", ALLEGRO_ALPHA},
{"inverse_alpha", ALLEGRO_INVERSE_ALPHA},
{"src_color", ALLEGRO_SRC_COLOR},
{"dest_color", ALLEGRO_DEST_COLOR},
{"inverse_src_color", ALLEGRO_INVERSE_SRC_COLOR},
{"inverse_dest_color", ALLEGRO_INVERSE_DEST_COLOR},
{NULL, 0}
};
static const mapping_t state_flag_mapping[] = {
{"new_display_parameters", ALLEGRO_STATE_NEW_DISPLAY_PARAMETERS},
{"new_bitmap_parameters", ALLEGRO_STATE_NEW_BITMAP_PARAMETERS},
{"display", ALLEGRO_STATE_DISPLAY},
{"target_bitmap", ALLEGRO_STATE_TARGET_BITMAP},
{"blender", ALLEGRO_STATE_BLENDER},
{"transform", ALLEGRO_STATE_TRANSFORM},
{"new_file_interface", ALLEGRO_STATE_NEW_FILE_INTERFACE},
{"bitmap", ALLEGRO_STATE_BITMAP},
{"target_bitmap", ALLEGRO_STATE_TARGET_BITMAP},
{"all", ALLEGRO_STATE_ALL},
{NULL, 0}
};
static const mapping_t joyflags_mapping[] = {
{"digital", ALLEGRO_JOYFLAG_DIGITAL},
{"analogue", ALLEGRO_JOYFLAG_ANALOGUE},
{NULL, 0}
};
static const mapping_t standard_path_mapping[] = {
{"resources", ALLEGRO_RESOURCES_PATH},
{"temp", ALLEGRO_TEMP_PATH},
{"user_home", ALLEGRO_USER_HOME_PATH},
{"user_documents", ALLEGRO_USER_DOCUMENTS_PATH},
{"user_data", ALLEGRO_USER_DATA_PATH},
{"user_settings", ALLEGRO_USER_SETTINGS_PATH},
{"exename", ALLEGRO_EXENAME_PATH},
{NULL, 0}
};
static const mapping_t mouse_cursor_mapping[] = {
{"default", ALLEGRO_SYSTEM_MOUSE_CURSOR_DEFAULT},
{"arrow", ALLEGRO_SYSTEM_MOUSE_CURSOR_ARROW},
{"busy", ALLEGRO_SYSTEM_MOUSE_CURSOR_BUSY},
{"question", ALLEGRO_SYSTEM_MOUSE_CURSOR_QUESTION},
{"edit", ALLEGRO_SYSTEM_MOUSE_CURSOR_EDIT},
{"move", ALLEGRO_SYSTEM_MOUSE_CURSOR_MOVE},
{"resize_n", ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_N},
{"resize_w", ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_W},
{"resize_s", ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_S},
{"resize_e", ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_E},
{"resize_nw", ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_NW},
{"resize_sw", ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_SW},
{"resize_se", ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_SE},
{"resize_ne", ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_NE},
{"progress", ALLEGRO_SYSTEM_MOUSE_CURSOR_PROGRESS},
{"precision", ALLEGRO_SYSTEM_MOUSE_CURSOR_PRECISION},
{"link", ALLEGRO_SYSTEM_MOUSE_CURSOR_LINK},
{"alt_select", ALLEGRO_SYSTEM_MOUSE_CURSOR_ALT_SELECT},
{"unavailable", ALLEGRO_SYSTEM_MOUSE_CURSOR_UNAVAILABLE},
{NULL, 0}
};
static const mapping_t keycode_mapping[] = {
{"A", ALLEGRO_KEY_A}, {"B", ALLEGRO_KEY_B}, {"C", ALLEGRO_KEY_C}, {"D", ALLEGRO_KEY_D},
{"E", ALLEGRO_KEY_E}, {"F", ALLEGRO_KEY_F}, {"G", ALLEGRO_KEY_G}, {"H", ALLEGRO_KEY_H},
{"I", ALLEGRO_KEY_I}, {"J", ALLEGRO_KEY_J}, {"K", ALLEGRO_KEY_K}, {"L", ALLEGRO_KEY_L},
10BC8
div> {"M", ALLEGRO_KEY_M}, {"N", ALLEGRO_KEY_N}, {"O", ALLEGRO_KEY_O}, {"P", ALLEGRO_KEY_P},
{"Q", ALLEGRO_KEY_Q}, {"R", ALLEGRO_KEY_R}, {"S", ALLEGRO_KEY_S}, {"T", ALLEGRO_KEY_T},
{"U", ALLEGRO_KEY_U}, {"V", ALLEGRO_KEY_V}, {"W", ALLEGRO_KEY_W}, {"X", ALLEGRO_KEY_X},
{"Y", ALLEGRO_KEY_Y}, {"Z", ALLEGRO_KEY_Z},
{"0", ALLEGRO_KEY_0}, {"1", ALLEGRO_KEY_1}, {"2", ALLEGRO_KEY_2}, {"3", ALLEGRO_KEY_3},
{"4", ALLEGRO_KEY_4}, {"5", ALLEGRO_KEY_5}, {"6", ALLEGRO_KEY_6}, {"7", ALLEGRO_KEY_7},
{"8", ALLEGRO_KEY_8}, {"9", ALLEGRO_KEY_9},
{"F1", ALLEGRO_KEY_F1}, {"F2", ALLEGRO_KEY_F2}, {"F3", ALLEGRO_KEY_F3}, {"F4", ALLEGRO_KEY_F4},
{"F5", ALLEGRO_KEY_F5}, {"F6", ALLEGRO_KEY_F6}, {"F7", ALLEGRO_KEY_F7}, {"F8", ALLEGRO_KEY_F8},
{"F9", ALLEGRO_KEY_F9}, {"F10", ALLEGRO_KEY_F10}, {"F11", ALLEGRO_KEY_F11}, {"F12", ALLEGRO_KEY_F12},
{"ESCAPE", ALLEGRO_KEY_ESCAPE}, {"TILDE", ALLEGRO_KEY_TILDE}, {"EQUALS", ALLEGRO_KEY_EQUALS},
{"BACKSPACE", ALLEGRO_KEY_BACKSPACE}, {"TAB", ALLEGRO_KEY_TAB}, {"OPENBRACE", ALLEGRO_KEY_OPENBRACE},
{"CLOSEBRACE", ALLEGRO_KEY_CLOSEBRACE}, {"ENTER", ALLEGRO_KEY_ENTER}, {"SEMICOLON", ALLEGRO_KEY_SEMICOLON},
{"QUOTE", ALLEGRO_KEY_QUOTE}, {"BACKSLASH", ALLEGRO_KEY_BACKSLASH}, {"BACKSLASH2", ALLEGRO_KEY_BACKSLASH2},
{"COMMA", ALLEGRO_KEY_COMMA}, {"FULLSTOP", ALLEGRO_KEY_FULLSTOP}, {"SLASH", ALLEGRO_KEY_SLASH},
{"SPACE", ALLEGRO_KEY_SPACE}, {"INSERT", ALLEGRO_KEY_INSERT}, {"DELETE", ALLEGRO_KEY_DELETE},
{"HOME", ALLEGRO_KEY_HOME}, {"END", ALLEGRO_KEY_END}, {"PGUP", ALLEGRO_KEY_PGUP},
{"PGDN", ALLEGRO_KEY_PGDN}, {"LEFT", ALLEGRO_KEY_LEFT}, {"RIGHT", ALLEGRO_KEY_RIGHT},
{"UP", ALLEGRO_KEY_UP}, {"DOWN", ALLEGRO_KEY_DOWN}, {"PAD_SLASH", ALLEGRO_KEY_PAD_SLASH},
{"PAD_ASTERISK", ALLEGRO_KEY_PAD_ASTERISK}, {"PAD_MINUS", ALLEGRO_KEY_PAD_MINUS},
{"PAD_PLUS", ALLEGRO_KEY_PAD_PLUS}, {"PAD_DELETE", ALLEGRO_KEY_PAD_DELETE}, {"PAD_ENTER", ALLEGRO_KEY_PAD_ENTER},
{"PRINTSCREEN", ALLEGRO_KEY_PRINTSCREEN}, {"PAUSE", ALLEGRO_KEY_PAUSE}, {"ABNT_C1", ALLEGRO_KEY_ABNT_C1},
{"YEN", ALLEGRO_KEY_YEN}, {"KANA", ALLEGRO_KEY_KANA}, {"CONVERT", ALLEGRO_KEY_CONVERT},
{"NOCONVERT", ALLEGRO_KEY_NOCONVERT}, {"AT", ALLEGRO_KEY_AT}, {"CIRCUMFLEX", ALLEGRO_KEY_CIRCUMFLEX},
{"COLON2", ALLEGRO_KEY_COLON2}, {"KANJI", ALLEGRO_KEY_KANJI}, {"LSHIFT", ALLEGRO_KEY_LSHIFT},
{"RSHIFT", ALLEGRO_KEY_RSHIFT}, {"LCTRL", ALLEGRO_KEY_LCTRL}, {"RCTRL", ALLEGRO_KEY_RCTRL},
{"ALT", ALLEGRO_KEY_ALT}, {"ALTGR", ALLEGRO_KEY_ALTGR}, {"LWIN", ALLEGRO_KEY_LWIN},
{"RWIN", ALLEGRO_KEY_RWIN}, {"MENU", ALLEGRO_KEY_MENU}, {"SCROLLLOCK", ALLEGRO_KEY_SCROLLLOCK},
{"NUMLOCK", ALLEGRO_KEY_NUMLOCK}, {"CAPSLOCK", ALLEGRO_KEY_CAPSLOCK}, {"PAD_EQUALS", ALLEGRO_KEY_PAD_EQUALS},
{"BACKQUOTE", ALLEGRO_KEY_BACKQUOTE}, {"SEMICOLON2", ALLEGRO_KEY_SEMICOLON2}, {"COMMAND", ALLEGRO_KEY_COMMAND},
{NULL, 0}
};
static const mapping_t keyboard_modifiers_mapping[] = {
{"shift", ALLEGRO_KEYMOD_SHIFT},
{"ctrl", ALLEGRO_KEYMOD_CTRL},
{"atl", ALLEGRO_KEYMOD_ALT},
{"lwin", ALLEGRO_KEYMOD_LWIN},
{"rwin", ALLEGRO_KEYMOD_RWIN},
{"menu", ALLEGRO_KEYMOD_MENU},
{"altgr", ALLEGRO_KEYMOD_ALTGR},
{"command", ALLEGRO_KEYMOD_COMMAND},
{"scrolllock", ALLEGRO_KEYMOD_SCROLLLOCK},
{"numlock", ALLEGRO_KEYMOD_NUMLOCK},
{"capslock", ALLEGRO_KEYMOD_CAPSLOCK},
{"inaltseq", ALLEGRO_KEYMOD_INALTSEQ},
{"accent1", ALLEGRO_KEYMOD_ACCENT1},
{"accent2", ALLEGRO_KEYMOD_ACCENT2},
{"accent3", ALLEGRO_KEYMOD_ACCENT3},
{"accent4", ALLEGRO_KEYMOD_ACCENT4},
{NULL, 0}
};
static const mapping_t audio_depth_mapping[] = {
{"int8", ALLEGRO_AUDIO_DEPTH_INT8},
{"int16", ALLEGRO_AUDIO_DEPTH_INT16},
{"int24", ALLEGRO_AUDIO_DEPTH_INT24},
{"float32", ALLEGRO_AUDIO_DEPTH_FLOAT32},
{"unsigned", ALLEGRO_AUDIO_DEPTH_UNSIGNED},
{"uint8", ALLEGRO_AUDIO_DEPTH_UINT8},
{"uint16", ALLEGRO_AUDIO_DEPTH_UINT16},
{"uint24", ALLEGRO_AUDIO_DEPTH_UINT24},
{NULL, 0}
};
static const mapping_t channel_conf_mapping[] = {
{"1", ALLEGRO_CHANNEL_CONF_1},
{"2", ALLEGRO_CHANNEL_CONF_2},
{"3", ALLEGRO_CHANNEL_CONF_3},
{"4", ALLEGRO_CHANNEL_CONF_4},
{"5_1", ALLEGRO_CHANNEL_CONF_5_1},
{"6_1", ALLEGRO_CHANNEL_CONF_6_1},
{"7_1", ALLEGRO_CHANNEL_CONF_7_1},
{NULL, 0}
};
static const mapping_t mixer_quality_mapping[] = {
{"point", ALLEGRO_MIXER_QUALITY_POINT},
{"linear", ALLEGRO_MIXER_QUALITY_LINEAR},
{"cubic", ALLEGRO_MIXER_QUALITY_CUBIC},
{NULL, 0}
};
static const mapping_t playmode_mapping[] = {
{"once", ALLEGRO_PLAYMODE_ONCE},
{"loop", ALLEGRO_PLAYMODE_LOOP},
{"bidir", ALLEGRO_PLAYMODE_BIDIR},
{NULL, 0}
};
static const mapping_t draw_text_mapping[] = {
{"left", ALLEGRO_ALIGN_LEFT},
{"right", ALLEGRO_ALIGN_RIGHT},
{"centre", ALLEGRO_ALIGN_CENTRE},
{"integer", ALLEGRO_ALIGN_INTEGER},
{NULL, 0}
};
static const mapping_t ttf_flag_mapping[] = {
{"no_kerning", ALLEGRO_TTF_NO_KERNING},
{"monochrome", ALLEGRO_TTF_MONOCHROME},
{"no_authohint", ALLEGRO_TTF_NO_AUTOHINT},
{NULL, 0}
};
static const mapping_t enet_packet_flag_mapping[] = {
{"reliable", ENET_PACKET_FLAG_RELIABLE},
{"unsequenced", ENET_PACKET_FLAG_UNSEQUENCED},
{"unreliable_fragment", ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT},
{"sent", ENET_PACKET_FLAG_SENT},
{NULL, 0}
};
/*
================================================================================
GENERAL ERROR MESSAGE DISPLAY
================================================================================
*/
#if defined(ALLEGRO_WINDOWS) || defined(ALLEGRO_MACOSX)
static void show_error( const char *message ) {
char title[512];
sprintf_s(title, sizeof(title), "Legato Runtime (%d.%d.%d)", LEGATO_VERSION_MAJOR, LEGATO_VERSION_MINOR, LEGATO_VERSION_PATCH);
al_show_native_message_box(NULL, title, "Fatal error:", message, NULL, ALLEGRO_MESSAGEBOX_ERROR);
}
#else
static void show_error( const char *message ) {
fprintf(stderr, "Legato Runtime (%d.%d.%d)\nFatal error:\n%s\n", LEGATO_VERSION_MAJOR, LEGATO_VERSION_MINOR, LEGATO_VERSION_PATCH, message);
}
#endif /* ALLEGRO_WINDOWS */
/*
================================================================================
LUA HELPERS
================================================================================
*/
int global_object_table_ref = LUA_NOREF;
static int push_ok( lua_State *L ) {
lua_pushboolean(L, 1);
return 1;
}
static int push_error( lua_State *L, const char *fmt, ... ) {
va_list va;
va_start(va, fmt);
lua_pushnil(L);
lua_pushvfstring(L, fmt, va);
va_end(va);
return 2;
}
static void *push_data( lua_State *L, const char *name, const size_t size ) {
void *data = lua_newuserdata(L, size);
if ( data == NULL ) {
luaL_error(L, "cannot allocate space for " LUA_QS, name);
}
luaL_setmetatable(L, name);
return data;
}
static int push_object_with_dependency( lua_State *L, const char *name, void *ptr, const int destroy, const int dependency ) {
object_t *obj;
if ( ptr ) {
#ifdef DEBUG_OBJECT_LIFE
printf("new object: %s (%p)\n", name, ptr);
#endif
obj = (object_t*) push_data(L, name, sizeof(object_t));
obj->ptr = ptr;
obj->name = name;
obj->destroy = destroy;
if ( dependency ) {
lua_pushvalue(L, dependency);
obj->dependency_ref = luaL_ref(L, LUA_REGISTRYINDEX);
} else {
obj->dependency_ref = LUA_NOREF;
}
lua_rawgeti(L, LUA_REGISTRYINDEX, global_object_table_ref); /* register new object in weak-ref table */
lua_pushlightuserdata(L, ptr);
lua_pushvalue(L, -3);
lua_settable(L, -3);
lua_pop(L, 1);
return 1;
} else {
return push_error(L, "cannot create object " LUA_QS, name);
}
}
static int push_object( lua_State *L, const char *name, void *ptr, const int destroy ) {
return push_object_with_dependency(L, name, ptr, destroy, 0);
}
static void *to_object( lua_State *L, const int idx, const char *name ) {
object_t *obj = (object_t*) luaL_checkudata(L, idx, name);
if ( obj->ptr == NULL ) {
luaL_error(L, "attempt to operate on destroyed " LUA_QS, name);
}
return obj->ptr;
}
static void *to_object_gc( lua_State *L, const int idx, const char *name ) {
object_t *obj = (object_t*) luaL_checkudata(L, idx, name);
if ( obj->ptr && obj->destroy ) {
return obj->ptr;
} else {
return NULL;
}
}
/* WARNING: this function does no sanity check!! Use it only after to_object/to_object_gc */
static void clear_object( lua_State *L, const int idx ) {
object_t *obj = (object_t*) lua_touserdata(L, idx);
#ifdef DEBUG_OBJECT_LIFE
printf("clear object: %s (%p)\n", obj->name, obj->ptr);
#endif
luaL_unref(L, LUA_REGISTRYINDEX, obj->dependency_ref);
obj->ptr = NULL;
obj->destroy = 0;
obj->dependency_ref = LUA_NOREF;
}
static void create_meta( lua_State *L, const char *name, const luaL_Reg funcs[] ) {
luaL_newmetatable(L, name);
lua_pushvalue(L, -1);
lua_setfield(L, -2, "__index");
luaL_setfuncs(L, funcs, 0);
lua_pop(L, 1);
}
static int parse_flag_table( lua_State *L, const int idx, const mapping_t mapping[] ) {
int i, flags = 0;
luaL_checktype(L, idx, LUA_TTABLE);
for ( i = 0; mapping[i].name; ++i ) {
lua_getfield(L, idx, mapping[i].name);
if ( ! lua_isnil(L, -1) ) {
if ( lua_toboolean(L, -1) ) {
flags |= mapping[i].value;
}
}
lua_pop(L, 1);
}
return flags;
}
static int parse_opt_flag_table( lua_State *L, const int idx, const mapping_t mapping[], const int flags ) {
if ( lua_istable(L, idx) ) {
return parse_flag_table(L, idx, mapping);
} else {
return flags;
}
}
static int push_flag_table( lua_State *L, const int flags, const mapping_t mapping[] ) {
int i;
lua_newtable(L);
for ( i = 0; mapping[i].name; ++i ) {
lua_pushboolean(L, flags & mapping[i].value);
lua_setfield(L, -2, mapping[i].name);
}
return 1;
}
static int parse_enum_name( lua_State *L, const int idx, const mapping_t mapping[] ) {
int i;
const char *name = luaL_checkstring(L, idx);
for ( i = 0; mapping[i].name; ++i ) {
if ( strcmp(name, mapping[i].name) == 0 ) {
return mapping[i].value;
}
}
luaL_argerror(L, idx, "invalid enum");
return 0;
}
static int push_enum_name( lua_State *L, const int value, const mapping_t mapping[] ) {
int i;
for ( i = 0; mapping[i].name; ++i ) {
if ( value == mapping[i].value ) {
lua_pushstring(L, mapping[i].name);
return 1;
}
}
return 0;
}
/*
static int push_equal_check( lua_State *L, const char *name ) {
object_t *ob1, *ob2;
ob1 = (object_t*) luaL_testudata(L, 1, name);
ob2 = (object_t*) luaL_testudata(L, 2, name);
if ( ob1 && ob2 ) {
if ( ob1->ptr || ob2->ptr ) {
lua_pushboolean(L, ob1->ptr == ob2->ptr);
} else {
lua_pushboolean(L, 0);
}
} else {
lua_pushboolean(L, 0);
}
return 1;
}
*/
static void create_object_table( lua_State *L ) {
/* create weak-value table for all created objects */
lua_newtable(L);
lua_newtable(L);
lua_pushstring(L, "v");
lua_setfield(L, -2, "__mode");
lua_setmetatable(L, -2);
global_object_table_ref = luaL_ref(L, LUA_REGISTRYINDEX);
}
static int push_object_by_pointer_with_dependency( lua_State *L, const char *name, void *ptr, const int dependency ) {
lua_rawgeti(L, LUA_REGISTRYINDEX, global_object_table_ref);
lua_pushlightuserdata(L, ptr);
lua_gettable(L, -2);
lua_remove(L, -2);
if ( lua_isnil(L, -1) ) {
lua_pop(L, 1);
return push_object_with_dependency(L, name, ptr, 0, dependency);
} else {
return 1;
}
}
static int push_object_by_pointer( lua_State *L, const char *name, void *ptr ) {
return push_object_by_pointer_with_dependency(L, name, ptr, 0);
}
static void set_str( lua_State *L, const char *key, const char *value ) {
lua_pushstring(L, value);
lua_setfield(L, -2, key);
}
static void set_int( lua_State *L, const char *key, const lua_Integer value ) {
lua_pushinteger(L, value);
lua_setfield(L, -2, key);
}
static void set_ptr( lua_State *L, const char *key, const char *name, const void *ptr ) {
push_object_by_pointer(L, name, (void*) ptr);
lua_setfield(L, -2, key);
}
static void set_bool( lua_State *L, const char *key, const int value ) {
lua_pushboolean(L, value);
lua_setfield(L, -2, key);
}
static void set_float( lua_State *L, const char *key, const float value ) {
lua_pushnumber(L, value);
lua_setfield(L, -2, key);
}
static void set_flags( lua_State *L, const char *key, const int flags, const mapping_t mapping[] ) {
push_flag_table(L, flags, mapping);
lua_setfield(L, -2, key);
}
static void register_mapping( lua_State *L, const mapping_t mapping[] ) {
int i;
for ( i = 0; mapping[i].name; ++i ) {
lua_pushinteger(L, mapping[i].value);
lua_setfield(L, -2, mapping[i].name);
}
}
/*
================================================================================
CORE - FUNCTIONS
================================================================================
*/
static int core_get_version( lua_State *L ) {
lua_pushinteger(L, LEGATO_VERSION_MAJOR);
lua_pushinteger(L, LEGATO_VERSION_MINOR);
lua_pushinteger(L, LEGATO_VERSION_PATCH);
return 3;
}
static int core_get_version_string( lua_State *L ) {
lua_pushfstring(L, "Legato Runtime (%d.%d.%d) - written by Sebastian Steinhauer",
LEGATO_VERSION_MAJOR, LEGATO_VERSION_MINOR, LEGATO_VERSION_PATCH);
return 1;
}
static const char *core_load_script_callback( lua_State *L, void *data, size_t *size ) {
static char buffer[4096];
PHYSFS_sint64 read_bytes = PHYSFS_read((PHYSFS_File*)data, buffer, 1, sizeof(buffer));
if ( read_bytes > 0 ) {
*size = (size_t) read_bytes;
return buffer;
} else {
*size = 0L;
return NULL;
}
}
static int core_load_script( lua_State *L ) {
int success;
PHYSFS_File *fp = PHYSFS_openRead(luaL_checkstring(L, 1));
if ( fp == NULL ) {
luaL_error(L, "cannot load lua script " LUA_QS, lua_tostring(L, 1));
}
lua_pushfstring(L, "@%s", lua_tostring(L, 1));
success = lua_load(L, core_load_script_callback, fp, lua_tostring(L, -1), NULL);
PHYSFS_close(fp);
lua_remove(L, -2);
if ( success == LUA_OK ) {
return 1;
} else {
lua_error(L);
return 0;
}
}
static int core_encode_UTF8_codepoint( lua_State *L ) {
char utf8str[4];
size_t utf8size;
utf8size = al_utf8_encode(utf8str, luaL_checkint(L, 1));
lua_pushlstring(L, utf8str, utf8size);
return 1;
}
static int core_get_UTF8_length( lua_State *L ) {
size_t size;
ALLEGRO_USTR_INFO info;
const char *data = luaL_checklstring(L, 1, &size);
lua_pushinteger(L, al_ustr_length(al_ref_buffer(&info, data, size)));
return 1;
}
static int core_split_UTF8_string( lua_State *L ) {
size_t str_size;
const ALLEGRO_USTR *ustr;
ALLEGRO_USTR_INFO info;
int i, pos;
int32_t codepoint;
const char *str = luaL_checklstring(L, 1, &str_size);
ustr = al_ref_buffer(&info, str, str_size);
lua_newtable(L);
for ( i = 1, pos = 0; (codepoint = al_ustr_get_next(ustr, &pos)) > 0; ++i ) {
lua_pushinteger(L, codepoint);
lua_rawseti(L, -2, i);
}
return 1;
}
static int core_get_licenses( lua_State *L ) {
lua_pushlstring(L, (const char*) licenses_txt, licenses_txt_len);
return 1;
}
static int core_get_os_type( lua_State *L ) {
#if defined(ALLEGRO_LINUX)
lua_pushliteral(L, "linux");
#elif defined(ALLEGRO_WINDOWS)
lua_pushliteral(L, "windows");
#elif defined(ALLEGRO_MACOSX)
lua_pushliteral(L, "macosx");
#elif defined(ALLEGRO_IPHONE)
lua_pushliteral(L, "iphone");
#elif defined(ALLEGRO_ANDROID)
lua_pushliteral(L, "android");
#elif defined(ALLEGRO_RASPBERRYPI)
lua_pushliteral(L, "raspberrypi");
#else
lua_pushliteral(L, "unknown");
#endif
return 1;
}
static const luaL_Reg core__functions[] = {
{"get_version", core_get_version},
{"get_version_string", core_get_version_string},
{"load_script", core_load_script},
{"encode_UTF8_codepoint", core_encode_UTF8_codepoint},
{"get_UTF8_length", core_get_UTF8_length},
{"split_UTF8_string", core_split_UTF8_string},
{"get_licenses", core_get_licenses},
{"get_os_type", core_get_os_type},
{NULL, NULL}
};
/*
================================================================================
ALLEGRO 5 - FUNCTIONS
================================================================================
*/
/*
================================================================================
Configuration files
================================================================================
*/
static int lg_create_config( lua_State *L ) {
return push_object(L, LEGATO_CONFIG, al_create_config(), 1);
}
static int lg_destroy_config( lua_State *L ) {
ALLEGRO_CONFIG *config = (ALLEGRO_CONFIG*) to_object_gc(L, 1, LEGATO_CONFIG);
if ( config ) {
al_destroy_config(config);
clear_object(L, 1);
}
return 0;
}
static int lg_load_config_file( lua_State *L ) {
return push_object(L, LEGATO_CONFIG, al_load_config_file(luaL_checkstring(L, 1)), 1);
}
static int lg_save_config_file( lua_State *L ) {
lua_pushboolean(L, al_save_config_file(luaL_checkstring(L, 2), to_config(L, 1)));
return 1;
}
static int lg_add_config_section( lua_State *L ) {
al_add_config
467E
_section(to_config(L, 1), luaL_checkstring(L, 2));
return 0;
}
static int lg_add_config_comment( lua_State *L ) {
al_add_config_comment(to_config(L, 1), luaL_checkstring(L, 2), luaL_checkstring(L, 3));
return 0;
}
static int lg_get_config_value( lua_State *L ) {
lua_pushstring(L, al_get_config_value(to_config(L, 1), luaL_checkstring(L, 2), luaL_checkstring(L, 3)));
return 1;
}
static int lg_set_config_value( lua_State *L ) {
al_set_config_value(to_config(L, 1), luaL_checkstring(L, 2), luaL_checkstring(L, 3), luaL_checkstring(L, 4));
return 0;
}
static int lg_get_config_sections( lua_State *L ) {
ALLEGRO_CONFIG *config;
ALLEGRO_CONFIG_SECTION *iterator;
const char *section;
int i;
config = to_config(L, 1);