-
Notifications
You must be signed in to change notification settings - Fork 62
/
wrap_imgui_impl.cpp
1346 lines (1192 loc) · 45.3 KB
/
wrap_imgui_impl.cpp
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
/**
* Copyright (c) 2006-2016 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#include "libimgui/imgui.h"
#include "libimgui/imgui_dock.h"
#include "imgui_impl.h"
#include "wrap_imgui_impl.h"
#include <vector>
#include <cstring>
#if defined(_WIN32) || defined(_WIN64)
#include <math.h>
// strndup() is not available on Windows
char *strndup( const char *s1, size_t n)
{
char *copy= (char*)malloc( n+1 );
memcpy( copy, s1, n );
copy[n] = 0;
return copy;
};
#endif
/*
** Love implentation functions
*/
static bool g_inited = false;
static int g_textures[250]; // Should be enough
static bool g_returnValueLast = true;
static int w_ShutDown(lua_State *L)
{
ShutDown();
return 0;
}
static int w_NewFrame(lua_State *L)
{
if (!g_inited)
{
Init(L);
g_inited = true;
}
NewFrame();
return 0;
}
// Util
const char* getRealDirectoryIfExists(lua_State *L, const char* relativePath)
{
if (L == nullptr || relativePath == nullptr)
{
return nullptr;
}
int originalStackSize = lua_gettop(L);
lua_getglobal(L, "love");
if (lua_isnil(L, -1))
{
lua_pop(L, 1);
return nullptr;
}
lua_getfield(L, -1, "filesystem");
lua_getfield(L, -1, "getRealDirectory");
lua_pushstring(L, relativePath);
lua_call(L, 1, 1);
char* result = nullptr;
if (!lua_isnil(L, -1))
{
size_t size = 0;
const char* tmp = lua_tolstring(L, -1, &size);
result = strndup(tmp, size);
}
lua_pop(L, lua_gettop(L) - originalStackSize);
return result;
}
// Inputs
static int w_MouseMoved(lua_State *L)
{
int x = (int)luaL_checknumber(L, 1);
int y = (int)luaL_checknumber(L, 2);
MouseMoved(x, y);
return 0;
}
static int w_MousePressed(lua_State *L)
{
int button = (int)luaL_checknumber(L, 1);
MousePressed(button);
return 0;
}
static int w_MouseReleased(lua_State *L)
{
int button = (int)luaL_checknumber(L, 1);
MouseReleased(button);
return 0;
}
static int w_WheelMoved(lua_State *L)
{
int y = (int)luaL_checknumber(L, 1);
WheelMoved(y);
return 0;
}
static int w_KeyPressed(lua_State *L)
{
size_t size;
const char *key = luaL_checklstring(L, 1, &size);
KeyPressed(key);
return 0;
}
static int w_KeyReleased(lua_State *L)
{
size_t size;
const char *key = luaL_checklstring(L, 1, &size);
KeyReleased(key);
return 0;
}
static int w_TextInput(lua_State *L)
{
size_t size;
const char *text = luaL_checklstring(L, 1, &size);
TextInput(text);
return 0;
}
static int w_GetWantCaptureMouse(lua_State *L)
{
lua_pushboolean(L, GetWantCaptureMouse());
return 1;
}
static int w_GetWantCaptureKeyboard(lua_State *L)
{
lua_pushboolean(L, GetWantCaptureKeyboard());
return 1;
}
static int w_GetWantTextInput(lua_State *L)
{
lua_pushboolean(L, GetWantTextInput());
return 1;
}
static int w_SetReturnValueLast(lua_State *L)
{
g_returnValueLast = (bool)lua_toboolean(L, 1);
return 0;
}
/*
** Custom bindings
*/
static int w_GetStyleColorName(lua_State *L)
{
int idx = luaL_checkint(L, 1);
lua_pushstring(L, ImGui::GetStyleColorName(idx - 1));
return 1;
}
static int w_GetStyleColCount(lua_State *L)
{
lua_pushinteger(L, ImGuiCol_COUNT);
return 1;
}
static int w_SetGlobalFontFromFileTTF(lua_State *L)
{
size_t size;
const char *path = luaL_checklstring(L, 1, &size);
float size_pixels = luaL_checknumber(L, 2);
float spacing_x = luaL_optnumber(L, 3, 0);
float spacing_y = luaL_optnumber(L, 4, 0);
float oversample_x = luaL_optnumber(L, 5, 1);
float oversample_y = luaL_optnumber(L, 6, 1);
const char* basePath = getRealDirectoryIfExists(L, path);
if (basePath == nullptr) {
lua_pushstring(L, "File does not exist.");
lua_error(L);
return 0;
}
char fullPath[4096] = {0};
snprintf(&(fullPath[0]), sizeof(fullPath) - 1, "%s/%s", basePath, path);
SetGlobalFontFromFileTTF(&(fullPath[0]), size_pixels, spacing_x, spacing_y,
oversample_x, oversample_y);
lua_settop(L, 0);
return 0;
}
static int w_AddFontFromFileTTF(lua_State *L) {
size_t filenameSize;
const char* filename = luaL_checklstring(L, 1, &filenameSize);
float pixelSize = luaL_checknumber(L, 2);
const char* basePath = getRealDirectoryIfExists(L, filename);
if (basePath == nullptr) {
lua_pushstring(L, "File does not exist.");
lua_error(L);
return 0;
}
char fullPath[4096] = {0};
snprintf(&(fullPath[0]), sizeof(fullPath) - 1, "%s/%s", basePath, filename);
ImFontConfig* fontCfg = (ImFontConfig*)lua_touserdata(L, 3);
ImGuiIO& io = ImGui::GetIO();
ImFont* font = io.Fonts->AddFontFromFileTTF(&(fullPath[0]), pixelSize);
lua_settop(L, 0);
if (font == nullptr) {
return luaL_error(L, "Could not load font");
} else {
lua_pushlightuserdata(L, (void*)font);
return 1;
}
}
/*
** Wrapped functions
*/
#define IMGUI_FUNCTION(name) \
static int impl_##name(lua_State *L) { \
int max_args = lua_gettop(L); \
int arg = 1; \
int stackval = 0;
#define TEXTURE_ARG(name) \
lua_getglobal(L, "imgui"); \
lua_pushvalue(L, arg++); \
lua_setfield(L, -2, "textureID"); \
luaL_dostring(L, "imgui.textures = imgui.textures or {}\
table.insert(imgui.textures, imgui.textureID)\
return #imgui.textures"); \
lua_pop(L, 1); \
int index = luaL_checkint(L, 0);\
g_textures[index - 1] = index; \
void *name = &g_textures[index - 1]; \
#define OPTIONAL_LABEL_ARG(name, value) \
const char* name; \
if (arg <= max_args) { \
name = lua_tostring(L, arg++); \
} else { \
name = value; \
}
#define LABEL_ARG(name) \
size_t i_##name##_size; \
const char * name = luaL_checklstring(L, arg++, &(i_##name##_size));
#define LABEL_POINTER_ARG(name) \
size_t i_##name##_size; \
const char * content = luaL_checklstring(L, arg++, &(i_##name##_size)); \
size_t buf_size = luaL_checknumber(L, arg++); \
char * name = new char [buf_size]; \
std::strcpy(name, content);
#define END_LABEL_POINTER(name) \
if (name != NULL) { \
lua_pushstring(L, name); \
delete[] name; \
stackval++; \
}
#define LABEL_ARRAY_ARG(name) \
luaL_checktype(L, arg, LUA_TTABLE); \
int len = lua_objlen(L, arg++); \
std::vector<const char *> list; \
for (int i = 0; i < len; i++) \
{ \
lua_pushinteger(L, i + 1); \
lua_gettable(L, arg - 1); \
size_t current_size; \
list.push_back(luaL_checklstring(L, -1, &(current_size))); \
} \
const char **name = list.data(); \
#define IM_VEC_2_ARG(name)\
const lua_Number i_##name##_x = luaL_checknumber(L, arg++); \
const lua_Number i_##name##_y = luaL_checknumber(L, arg++); \
ImVec2 name((float)i_##name##_x, (float)i_##name##_y);
#define OPTIONAL_IM_VEC_2_ARG(name, x, y) \
lua_Number i_##name##_x = x; \
lua_Number i_##name##_y = y; \
if (arg <= max_args - 1) { \
i_##name##_x = luaL_checknumber(L, arg++); \
i_##name##_y = luaL_checknumber(L, arg++); \
} \
const ImVec2 name((float)i_##name##_x, (float)i_##name##_y);
#define IM_VEC_4_ARG(name)\
const lua_Number i_##name##_x = luaL_checknumber(L, arg++); \
const lua_Number i_##name##_y = luaL_checknumber(L, arg++); \
const lua_Number i_##name##_z = luaL_checknumber(L, arg++); \
const lua_Number i_##name##_w = luaL_checknumber(L, arg++); \
const ImVec4 name((float)i_##name##_x, (float)i_##name##_y, (float)i_##name##_z, (float)i_##name##_w);
#define OPTIONAL_IM_VEC_4_ARG(name, x, y, z, w) \
lua_Number i_##name##_x = x; \
lua_Number i_##name##_y = y; \
lua_Number i_##name##_z = z; \
lua_Number i_##name##_w = w; \
if (arg <= max_args - 1) { \
i_##name##_x = luaL_checknumber(L, arg++); \
i_##name##_y = luaL_checknumber(L, arg++); \
i_##name##_z = luaL_checknumber(L, arg++); \
i_##name##_w = luaL_checknumber(L, arg++); \
} \
const ImVec4 name((float)i_##name##_x, (float)i_##name##_y, (float)i_##name##_z, (float)i_##name##_w);
#define NUMBER_ARG(name)\
lua_Number name = luaL_checknumber(L, arg++);
#define OPTIONAL_NUMBER_ARG(name, otherwise)\
lua_Number name = otherwise; \
if (arg <= max_args) { \
name = luaL_checknumber(L, arg++); \
}
#define FLOAT_POINTER_ARG(name) \
float i_##name##_value = (float)luaL_checknumber(L, arg++); \
float* name = &(i_##name##_value);
#define END_FLOAT_POINTER(name) \
if (name != NULL) { \
lua_pushnumber(L, i_##name##_value); \
stackval++; \
}
#define FLOAT_ARRAY_ARG(name) \
luaL_checktype(L, arg, LUA_TTABLE); \
int len = lua_objlen(L, arg++); \
std::vector<float> list; \
for (int i = 0; i < len; i++) \
{ \
lua_pushinteger(L, i + 1); \
lua_gettable(L, arg - 1); \
list.push_back(luaL_checknumber(L, -1)); \
} \
const float *name = list.data(); \
#define FLOAT_ARRAY2_ARG(name) \
float i_##name##_1 = (float)luaL_checknumber(L, arg++); \
float i_##name##_2 = (float)luaL_checknumber(L, arg++); \
float name[2] = { i_##name##_1, i_##name##_2 };
#define END_FLOAT_ARRAY2(name) \
lua_pushnumber(L, name[0]); \
lua_pushnumber(L, name[1]); \
stackval += 2; \
#define FLOAT_ARRAY3_ARG(name) \
float i_##name##_1 = (float)luaL_checknumber(L, arg++); \
float i_##name##_2 = (float)luaL_checknumber(L, arg++); \
float i_##name##_3 = (float)luaL_checknumber(L, arg++); \
float name[3] = { i_##name##_1, i_##name##_2, i_##name##_3 };
#define END_FLOAT_ARRAY3(name) \
lua_pushnumber(L, name[0]); \
lua_pushnumber(L, name[1]); \
lua_pushnumber(L, name[2]); \
stackval += 3; \
#define FLOAT_ARRAY4_ARG(name) \
float i_##name##_1 = (float)luaL_checknumber(L, arg++); \
float i_##name##_2 = (float)luaL_checknumber(L, arg++); \
float i_##name##_3 = (float)luaL_checknumber(L, arg++); \
float i_##name##_4 = (float)luaL_checknumber(L, arg++); \
float name[4] = { i_##name##_1, i_##name##_2, i_##name##_3, i_##name##_4 };
#define END_FLOAT_ARRAY4(name) \
lua_pushnumber(L, name[0]); \
lua_pushnumber(L, name[1]); \
lua_pushnumber(L, name[2]); \
lua_pushnumber(L, name[3]); \
stackval += 4; \
#define INT_ARRAY2_ARG(name) \
int i_##name##_1 = (int)luaL_checkinteger(L, arg++); \
int i_##name##_2 = (int)luaL_checkinteger(L, arg++); \
int name[2] = { i_##name##_1, i_##name##_2 };
#define END_INT_ARRAY2(name) \
lua_pushnumber(L, name[0]); \
lua_pushnumber(L, name[1]); \
stackval += 2; \
#define INT_ARRAY3_ARG(name) \
int i_##name##_1 = (int)luaL_checkinteger(L, arg++); \
int i_##name##_2 = (int)luaL_checkinteger(L, arg++); \
int i_##name##_3 = (int)luaL_checkinteger(L, arg++); \
int name[3] = { i_##name##_1, i_##name##_2, i_##name##_3 };
#define END_INT_ARRAY3(name) \
lua_pushnumber(L, name[0]); \
lua_pushnumber(L, name[1]); \
lua_pushnumber(L, name[2]); \
stackval += 3; \
#define INT_ARRAY4_ARG(name) \
int i_##name##_1 = (int)luaL_checkinteger(L, arg++); \
int i_##name##_2 = (int)luaL_checkinteger(L, arg++); \
int i_##name##_3 = (int)luaL_checkinteger(L, arg++); \
int i_##name##_4 = (int)luaL_checkinteger(L, arg++); \
int name[4] = { i_##name##_1, i_##name##_2, i_##name##_3, i_##name##_4 };
#define END_INT_ARRAY4(name) \
lua_pushnumber(L, name[0]); \
lua_pushnumber(L, name[1]); \
lua_pushnumber(L, name[2]); \
lua_pushnumber(L, name[3]); \
stackval += 4; \
#define OPTIONAL_INT_ARG(name, otherwise)\
int name = otherwise; \
if (arg <= max_args) { \
name = (int)luaL_checkinteger(L, arg++); \
}
#define INT_ARG(name) \
const int name = (int)luaL_checkinteger(L, arg++);
#define OPTIONAL_ENUM_ARG(name, otherwise)\
int name = otherwise; \
if (arg <= max_args) { \
if (lua_istable(L, arg++)) { \
int len = lua_objlen(L, -1); \
for (int i = 0; i < len; i++) { \
lua_pushinteger(L, i + 1); \
lua_gettable(L, arg - 1); \
lua_pushvalue(L, -1); \
lua_gettable(L, lua_upvalueindex(1)); \
name = name | (int)lua_tonumber(L, -1); \
lua_pop(L, 1); \
} \
} else { \
lua_pushvalue(L, arg - 1); \
lua_gettable(L, lua_upvalueindex(1)); \
name = (int)lua_tonumber(L, -1); \
lua_pop(L, 1); \
} \
}
#define ENUM_ARG(name) \
int name = 0; \
if (lua_istable(L, arg++)) { \
int len = lua_objlen(L, -1); \
for (int i = 0; i < len; i++) { \
lua_pushinteger(L, i + 1); \
lua_gettable(L, arg - 1); \
lua_pushvalue(L, -1); \
lua_gettable(L, lua_upvalueindex(1)); \
name = name | (int)lua_tonumber(L, -1); \
lua_pop(L, 1); \
} \
} else { \
lua_pushvalue(L, arg - 1); \
lua_gettable(L, lua_upvalueindex(1)); \
name = (int)lua_tonumber(L, -1); \
lua_pop(L, 1); \
}
#define OPTIONAL_UINT_ARG(name, otherwise)\
unsigned int name = otherwise; \
if (arg <= max_args) { \
name = (unsigned int)luaL_checkint(L, arg++); \
}
#define UINT_ARG(name) \
const unsigned int name = (unsigned int)luaL_checkinteger(L, arg++);
#define INT_POINTER_ARG(name) \
int i_##name##_value = (int)luaL_checkinteger(L, arg++); \
int* name = &(i_##name##_value);
#define END_INT_POINTER(name) \
if (name != NULL) { \
lua_pushnumber(L, i_##name##_value); \
stackval++; \
}
#define INT_CURRENT_ITEM_POINTER_ARG(name) \
int i_##name##_value = (int)luaL_checkinteger(L, arg++) - 1; \
int* name = &(i_##name##_value);
#define END_INT_CURRENT_ITEM_POINTER(name) \
if (name != NULL) { \
lua_pushnumber(L, i_##name##_value + 1); \
stackval++; \
}
#define UINT_POINTER_ARG(name) \
unsigned int i_##name##_value = (unsigned int)luaL_checkinteger(L, arg++); \
unsigned int* name = &(i_##name##_value);
#define END_UINT_POINTER(name) \
if (name != NULL) { \
lua_pushnumber(L, i_##name##_value); \
stackval++; \
}
#define BOOL_POINTER_ARG(name) \
bool i_##name##_value = (bool)lua_toboolean(L, arg++); \
bool* name = &(i_##name##_value);
#define OPTIONAL_BOOL_POINTER_ARG(name) \
bool i_##name##_value; \
bool* name = NULL; \
if (arg <= max_args) { \
if (lua_isboolean(L, arg++)) \
{ \
i_##name##_value = (bool)lua_toboolean(L, arg - 1); \
name = &(i_##name##_value); \
} \
}
#define OPTIONAL_BOOL_ARG(name, otherwise) \
bool name = otherwise; \
if (arg <= max_args) { \
name = (bool)lua_toboolean(L, arg++); \
}
#define DEFAULT_ARG(type, name, value) \
type name = value; \
#define BOOL_ARG(name) \
bool name = (bool)lua_toboolean(L, arg++);
#define CALL_FUNCTION(name, retType,...) \
retType ret = ImGui::name(__VA_ARGS__);
#define CALL_FUNCTION_NO_RET(name, ...) \
ImGui::name(__VA_ARGS__);
#define PUSH_NUMBER(name) \
if (!g_returnValueLast) { \
lua_pushnumber(L, name); \
stackval++; \
}
#define PUSH_STRING(name) \
if (!g_returnValueLast) { \
lua_pushstring(L, name); \
stackval++; \
}
#define PUSH_BOOL(name) \
if (!g_returnValueLast) { \
lua_pushboolean(L, (int) name); \
stackval++; \
}
#define PUSH_LAST_NUMBER(name) \
if (g_returnValueLast) { \
lua_pushnumber(L, name); \
stackval++; \
}
#define PUSH_LAST_STRING(name) \
if (g_returnValueLast) { \
lua_pushstring(L, name); \
stackval++; \
}
#define PUSH_LAST_BOOL(name) \
if (g_returnValueLast) { \
lua_pushboolean(L, (int) name); \
stackval++; \
}
#define END_BOOL_POINTER(name) \
if (name != NULL) { \
lua_pushboolean(L, (int)i_##name##_value); \
stackval++; \
}
#define END_IMGUI_FUNC \
return stackval; \
}
#ifdef ENABLE_IM_LUA_END_STACK
#define IF_RET_ADD_END_STACK(type) \
if (ret) { \
AddToStack(type); \
}
#define ADD_END_STACK(type) \
AddToStack(type);
#define POP_END_STACK(type) \
PopEndStack(type);
#define END_STACK_START \
static void ImEndStack(int type) { \
switch(type) {
#define END_STACK_OPTION(type, function) \
case type: \
ImGui::function(); \
break;
#define END_STACK_END \
} \
}
#else
#define END_STACK_START
#define END_STACK_OPTION(type, function)
#define END_STACK_END
#define IF_RET_ADD_END_STACK(type)
#define ADD_END_STACK(type)
#define POP_END_STACK(type)
#endif
#include "imgui_iterator.h"
#include "imgui_iterator_dock.h"
/*
** Hand made overrides
*/
static int w_Value(lua_State *L)
{
if (lua_isboolean(L, 2))
{
return impl_Value(L);
}
return impl_Value_4(L);
}
static int w_CollapsingHeader(lua_State *L)
{
if (lua_isboolean(L, 2))
{
return impl_CollapsingHeader_2(L);
}
return impl_CollapsingHeader(L);
}
static int w_TreeNodeEx(lua_State *L)
{
if (lua_gettop(L) > 2)
{
return impl_TreeNodeEx_2(L);
}
return impl_TreeNodeEx(L);
}
static int w_TreeNode(lua_State *L)
{
if (lua_gettop(L) > 1)
{
return impl_TreeNode_2(L);
}
return impl_TreeNode(L);
}
static int w_Combo(lua_State *L)
{
if (lua_isstring(L, 3))
{
return impl_Combo_2(L);
}
return impl_Combo(L);
}
static int w_RadioButton(lua_State *L)
{
if (lua_gettop(L) > 2)
{
return impl_RadioButton_2(L);
}
return impl_RadioButton(L);
}
static int w_PushID(lua_State *L)
{
if (lua_gettop(L) > 1)
{
return impl_PushID_2(L);
}
return impl_PushID(L);
}
static int w_GetID(lua_State *L)
{
if (lua_gettop(L) > 1)
{
return impl_GetID_2(L);
}
return impl_GetID(L);
}
static int w_PushStyleVar(lua_State *L)
{
if (lua_gettop(L) > 2)
{
return impl_PushStyleVar_2(L);
}
return impl_PushStyleVar(L);
}
static int w_PushStyleColor(lua_State *L)
{
if (lua_gettop(L) > 2)
{
return impl_PushStyleColor_2(L);
}
return impl_PushStyleColor(L);
}
static int w_SetWindowPos(lua_State *L)
{
if (lua_isstring(L, 1))
{
return impl_SetWindowPos_2(L);
}
return impl_SetWindowPos(L);
}
static int w_SetWindowSize(lua_State *L)
{
if (lua_isstring(L, 1))
{
return impl_SetWindowSize_2(L);
}
return impl_SetWindowSize(L);
}
static int w_SetWindowCollapsed(lua_State *L)
{
if (lua_isstring(L, 1))
{
return impl_SetWindowCollapsed_2(L);
}
return impl_SetWindowCollapsed(L);
}
static int w_SetWindowFocus(lua_State *L)
{
if (lua_isstring(L, 1))
{
return impl_SetWindowFocus_2(L);
}
return impl_SetWindowFocus(L);
}
static int w_BeginChild(lua_State *L)
{
if (lua_isstring(L, 1))
{
return impl_BeginChild(L);
}
return impl_BeginChild_2(L);
}
/*
** Reg
*/
static const struct luaL_Reg imguilib[] = {
#undef IMGUI_FUNCTION
#define IMGUI_FUNCTION(name) {#name, impl_##name},
// These defines are just redefining everything to nothing so
// we can get the function names
#undef DEFAULT_ARG
#define DEFAULT_ARG(type, name, value)
#undef TEXTURE_ARG
#define TEXTURE_ARG(name)
#undef OPTIONAL_LABEL_ARG
#define OPTIONAL_LABEL_ARG(name, value)
#undef LABEL_ARG
#define LABEL_ARG(name)
#undef LABEL_POINTER_ARG
#define LABEL_POINTER_ARG(name)
#undef END_LABEL_POINTER
#define END_LABEL_POINTER(name)
#undef LABEL_ARRAY_ARG
#define LABEL_ARRAY_ARG(name)
#undef IM_VEC_2_ARG
#define IM_VEC_2_ARG(name)
#undef OPTIONAL_IM_VEC_2_ARG
#define OPTIONAL_IM_VEC_2_ARG(name, x, y)
#undef IM_VEC_4_ARG
#define IM_VEC_4_ARG(name)
#undef OPTIONAL_IM_VEC_4_ARG
#define OPTIONAL_IM_VEC_4_ARG(name, x, y, z, w)
#undef NUMBER_ARG
#define NUMBER_ARG(name)
#undef OPTIONAL_NUMBER_ARG
#define OPTIONAL_NUMBER_ARG(name, otherwise)
#undef FLOAT_POINTER_ARG
#define FLOAT_POINTER_ARG(name)
#undef END_FLOAT_POINTER
#define END_FLOAT_POINTER(name)
#undef FLOAT_ARRAY_ARG
#define FLOAT_ARRAY_ARG(name)
#undef FLOAT_ARRAY2_ARG
#define FLOAT_ARRAY2_ARG(name)
#undef END_FLOAT_ARRAY2
#define END_FLOAT_ARRAY2(name)
#undef FLOAT_ARRAY3_ARG
#define FLOAT_ARRAY3_ARG(name)
#undef END_FLOAT_ARRAY3
#define END_FLOAT_ARRAY3(name)
#undef FLOAT_ARRAY4_ARG
#define FLOAT_ARRAY4_ARG(name)
#undef END_FLOAT_ARRAY4
#define END_FLOAT_ARRAY4(name)
#undef INT_ARRAY2_ARG
#define INT_ARRAY2_ARG(name)
#undef END_INT_ARRAY2
#define END_INT_ARRAY2(name)
#undef INT_ARRAY3_ARG
#define INT_ARRAY3_ARG(name)
#undef END_INT_ARRAY3
#define END_INT_ARRAY3(name)
#undef INT_ARRAY4_ARG
#define INT_ARRAY4_ARG(name)
#undef END_INT_ARRAY4
#define END_INT_ARRAY4(name)
#undef OPTIONAL_INT_ARG
#define OPTIONAL_INT_ARG(name, otherwise)
#undef INT_ARG
#define INT_ARG(name)
#undef OPTIONAL_ENUM_ARG
#define OPTIONAL_ENUM_ARG(name, otherwise)
#undef ENUM_ARG
#define ENUM_ARG(name)
#undef OPTIONAL_UINT_ARG
#define OPTIONAL_UINT_ARG(name, otherwise)
#undef UINT_ARG
#define UINT_ARG(name)
#undef INT_POINTER_ARG
#define INT_POINTER_ARG(name)
#undef END_INT_POINTER
#define END_INT_POINTER(name)
#undef INT_CURRENT_ITEM_POINTER_ARG
#define INT_CURRENT_ITEM_POINTER_ARG(name)
#undef END_INT_CURRENT_ITEM_POINTER
#define END_INT_CURRENT_ITEM_POINTER(name)
#undef UINT_POINTER_ARG
#define UINT_POINTER_ARG(name)
#undef END_UINT_POINTER
#define END_UINT_POINTER(name)
#undef BOOL_POINTER_ARG
#define BOOL_POINTER_ARG(name)
#undef OPTIONAL_BOOL_POINTER_ARG
#define OPTIONAL_BOOL_POINTER_ARG(name)
#undef OPTIONAL_BOOL_ARG
#define OPTIONAL_BOOL_ARG(name, otherwise)
#undef BOOL_ARG
#define BOOL_ARG(name)
#undef CALL_FUNCTION
#define CALL_FUNCTION(name, retType, ...)
#undef CALL_FUNCTION_NO_RET
#define CALL_FUNCTION_NO_RET(name, ...)
#undef PUSH_NUMBER
#define PUSH_NUMBER(name)
#undef PUSH_BOOL
#define PUSH_BOOL(name)
#undef PUSH_STRING
#define PUSH_STRING(name)
#undef PUSH_LAST_NUMBER
#define PUSH_LAST_NUMBER(name)
#undef PUSH_LAST_BOOL
#define PUSH_LAST_BOOL(name)
#undef PUSH_LAST_STRING
#define PUSH_LAST_STRING(name)
#undef END_BOOL_POINTER
#define END_BOOL_POINTER(name)
#undef END_IMGUI_FUNC
#define END_IMGUI_FUNC
#undef END_STACK_START
#define END_STACK_START
#undef END_STACK_OPTION
#define END_STACK_OPTION(type, function)
#undef END_STACK_END
#define END_STACK_END
#undef IF_RET_ADD_END_STACK
#define IF_RET_ADD_END_STACK(type)
#undef ADD_END_STACK
#define ADD_END_STACK(type)
#undef POP_END_STACK
#define POP_END_STACK(type)
#include "imgui_iterator.h"
#include "imgui_iterator_dock.h"
// Custom
{ "GetStyleColName", w_GetStyleColorName },
{ "GetStyleColCount", w_GetStyleColCount },
{ "SetGlobalFontFromFileTTF", w_SetGlobalFontFromFileTTF },
{ "AddFontFromFileTTF", w_AddFontFromFileTTF },
// Overrides
{ "Value", w_Value },
{ "CollapsingHeader", w_CollapsingHeader },
{ "Combo", w_Combo },
{ "RadioButton", w_RadioButton },
{ "PushID", w_PushID },
{ "GetID", w_GetID },
{ "PushStyleVar", w_PushStyleVar },
{ "PushStyleColor", w_PushStyleColor },
{ "SetWindowPos", w_SetWindowPos },
{ "SetWindowSize", w_SetWindowSize },
{ "SetWindowCollapsed", w_SetWindowCollapsed },
{ "SetWindowFocus", w_SetWindowFocus },
{ "BeginChild", w_BeginChild },
// Implementation
{ "ShutDown", w_ShutDown },
{ "NewFrame", w_NewFrame },
{ "MouseMoved", w_MouseMoved },
{ "MousePressed", w_MousePressed },
{ "MouseReleased", w_MouseReleased },
{ "WheelMoved", w_WheelMoved },
{ "KeyPressed", w_KeyPressed },
{ "KeyReleased", w_KeyReleased },
{ "TextInput", w_TextInput },
{ "GetWantCaptureKeyboard", w_GetWantCaptureKeyboard },
{ "GetWantCaptureMouse", w_GetWantCaptureMouse },
{ "GetWantTextInput", w_GetWantTextInput },
// Return value ordering
{ "SetReturnValueLast", w_SetReturnValueLast },
{ NULL, NULL }
};
extern "C" {
void luax_register(lua_State *L, const char *name, const luaL_Reg *l);
}
#define WRAP_ENUM(L, name, val) \
lua_pushlstring(L, #name, sizeof(#name)-1); \
lua_pushnumber(L, val); \
lua_settable(L, -3);
extern "C" LOVE_IMGUI_EXPORT int luaopen_imgui(lua_State *L)
{
// Enums not handled by iterator yet
lua_newtable(L);
// ImGuiWindowFlags, prefer using the ImGuiXXX_ version instead of the short version as it's deprecated and will be removed
WRAP_ENUM(L, NoTitleBar, ImGuiWindowFlags_NoTitleBar);
WRAP_ENUM(L, NoResize, ImGuiWindowFlags_NoResize);
WRAP_ENUM(L, NoMove, ImGuiWindowFlags_NoMove);
WRAP_ENUM(L, NoScrollbar, ImGuiWindowFlags_NoScrollbar);
WRAP_ENUM(L, NoScrollWithMouse, ImGuiWindowFlags_NoScrollWithMouse);
WRAP_ENUM(L, NoCollapse, ImGuiWindowFlags_NoCollapse);
WRAP_ENUM(L, AlwaysAutoResize, ImGuiWindowFlags_AlwaysAutoResize);
WRAP_ENUM(L, NoSavedSettings, ImGuiWindowFlags_NoSavedSettings);
WRAP_ENUM(L, NoInputs, ImGuiWindowFlags_NoInputs);
WRAP_ENUM(L, MenuBar, ImGuiWindowFlags_MenuBar);
WRAP_ENUM(L, HorizontalScrollbar, ImGuiWindowFlags_HorizontalScrollbar);
WRAP_ENUM(L, NoFocusOnAppearing, ImGuiWindowFlags_NoFocusOnAppearing);
WRAP_ENUM(L, NoBringToFrontOnFocus, ImGuiWindowFlags_NoBringToFrontOnFocus);
WRAP_ENUM(L, AlwaysVerticalScrollbar, ImGuiWindowFlags_AlwaysVerticalScrollbar);
WRAP_ENUM(L, AlwaysHorizontalScrollbar, ImGuiWindowFlags_AlwaysHorizontalScrollbar);
WRAP_ENUM(L, AlwaysUseWindowPadding, ImGuiWindowFlags_AlwaysUseWindowPadding);
WRAP_ENUM(L, ResizeFromAnySide, ImGuiWindowFlags_ResizeFromAnySide);
WRAP_ENUM(L, ImGuiWindowFlags_NoTitleBar, ImGuiWindowFlags_NoTitleBar);
WRAP_ENUM(L, ImGuiWindowFlags_NoResize, ImGuiWindowFlags_NoResize);
WRAP_ENUM(L, ImGuiWindowFlags_NoMove, ImGuiWindowFlags_NoMove);