1 
2 //          Copyright 2019 - 2021 Michael D. Parker
3 // Distributed under the Boost Software License, Version 1.0.
4 //    (See accompanying file LICENSE_1_0.txt or copy at
5 //          http://www.boost.org/LICENSE_1_0.txt)
6 
7 module bindbc.lua.v54.types;
8 
9 version(LUA_54):
10 
11 import core.stdc.stdio : BUFSIZ, FILE;
12 import core.stdc.stdint : intptr_t;
13 import core.stdc.config : c_long;
14 
15 // luaconf.h
16 alias LUA_INT32 = int;
17 alias LUAI_UMEM = size_t;
18 alias LUAI_MEM = ptrdiff_t;
19 alias LUA_NUMBER = double;
20 alias LUA_INTEGER = ptrdiff_t;
21 alias LUA_UNSIGNED = uint;
22 
23 alias LUA_KCONTEXT =  intptr_t;
24 enum LUAI_MAXSTACK = 1000000;
25 enum LUA_EXTRASPACE = (void*).sizeof;
26 enum LUA_IDSIZE = 60;
27 enum LUAL_BUFFERSIZE = cast(int)(16 * (void*).sizeof * lua_Number.sizeof);
28 
29 mixin template LUAI_MAXALIGN() {
30     lua_Number n;
31     double u;
32     void *s;
33     lua_Integer i;
34     c_long l;
35 }
36 
37 
38 // lauxlib.h
39 enum LUA_ERRFILE = LUA_ERRERR+1;
40 enum LUA_LOADED_TABLE = "_LOADED";
41 enum LUA_PRELOAD_TABLE = "_PRELOAD";
42 
43 struct luaL_Reg {
44     const(char)* name;
45     lua_CFunction func;
46 }
47 
48 enum LUAL_NUMSIZES = lua_Integer.sizeof * 16 + lua_Number.sizeof;
49 
50 enum LUA_NOREF = -2;
51 enum LUA_REFNIL = -1;
52 
53 struct luaL_Buffer {
54     char* b;
55     size_t size;
56     size_t n;
57     lua_State* L;
58     union init {
59         mixin LUAI_MAXALIGN!();
60         char[LUAL_BUFFERSIZE] initb;
61     }
62 }
63 
64 alias LUA_FILEHANDLE = FILE*;
65 
66 struct luaL_Stream {
67     FILE* f;
68     lua_CFunction closef;
69 }
70 
71 // lua.h
72 enum LUA_VERSION_MAJOR = "5";
73 enum LUA_VERSION_MINOR = "4";
74 enum LUA_VERSION_RELEASE = "2";
75 
76 enum LUA_VERSION_NUM = 504;
77 enum LUA_VERSION_RELEASE_NUM = LUA_VERSION_NUM * 100 + 0;
78 
79 enum LUA_VERSION = "Lua " ~ LUA_VERSION_MAJOR ~ "." ~ LUA_VERSION_MINOR;
80 enum LUA_RELEASE = LUA_VERSION ~ "." ~ LUA_VERSION_RELEASE;
81 
82 enum LUA_SIGNATURE = "\x1bLua";
83 enum LUA_MULTRET = -1;
84 
85 enum LUA_REGISTRYINDEX = -LUAI_MAXSTACK - 1000;
86 
87 enum LUA_OK = 0;
88 enum LUA_YIELD = 1;
89 enum LUA_ERRRUN = 2;
90 enum LUA_ERRSYNTAX = 3;
91 enum LUA_ERRMEM = 4;
92 enum LUA_ERRERR = 5;
93 
94 enum LUA_TNONE = -1;
95 enum LUA_TNIL = 0;
96 enum LUA_TBOOLEAN = 1;
97 enum LUA_TLIGHTUSERDATA = 2;
98 enum LUA_TNUMBER = 3;
99 enum LUA_TSTRING = 4;
100 enum LUA_TTABLE = 5;
101 enum LUA_TFUNCTION = 6;
102 enum LUA_TUSERDATA = 7;
103 enum LUA_TTHREAD = 8;
104 enum LUA_NUMTYPES = 9;
105 
106 alias LUA_NUMTAGS = LUA_NUMTYPES;
107 
108 enum LUA_MINSTACK = 20;
109 
110 enum LUA_RIDX_MAINTHREAD = 1;
111 enum LUA_RIDX_GLOBALS = 2;
112 enum LUA_RIDX_LAST = LUA_RIDX_GLOBALS;
113 
114 alias lua_Number = LUA_NUMBER;
115 alias lua_Integer = LUA_INTEGER;
116 alias lua_Unsigned = LUA_UNSIGNED;
117 alias lua_KContext = LUA_KCONTEXT;
118 
119 struct lua_State;
120 
121 nothrow {
122     alias lua_CFunction = int function(lua_State* L);
123     alias lua_KFunction = int function(lua_State* L, int status, lua_KContext ctx);
124     alias lua_Reader = const(char)* function(lua_State* L, void* ud, size_t sz);
125     alias lua_Writer = int function(lua_State* L, const(void)* p, size_t sz, void* ud);
126     alias lua_Alloc = void* function(void* ud, void* ptr, size_t osize, size_t nsize);
127     alias lua_WarnFunction = void function(void* ud, const(char)* msg, int tocont);
128 }
129 
130 
131 enum LUA_OPADD = 0;
132 enum LUA_OPSUB = 1;
133 enum LUA_OPMUL = 2;
134 enum LUA_OPMOD = 3;
135 enum LUA_OPPOW = 4;
136 enum LUA_OPDIV = 5;
137 enum LUA_OPIDIV = 6;
138 enum LUA_OPBAND = 7;
139 enum LUA_OPBOR = 8;
140 enum LUA_OPBXOR = 9;
141 enum LUA_OPSHL = 10;
142 enum LUA_OPSHR = 11;
143 enum LUA_OPUNM = 12;
144 enum LUA_OPBNOT = 13;
145 
146 enum LUA_OPEQ = 0;
147 enum LUA_OPLT = 1;
148 enum LUA_OPLE = 2;
149 
150 enum LUA_GCSTOP = 0;
151 enum LUA_GCRESTART = 1;
152 enum LUA_GCCOLLECT = 2;
153 enum LUA_GCCOUNT = 3;
154 enum LUA_GCCOUNTB = 4;
155 enum LUA_GCSTEP = 5;
156 enum LUA_GCSETPAUSE = 6;
157 enum LUA_GCSETSTEPMUL = 7;
158 enum LUA_GCISRUNNING = 9;
159 
160 enum LUA_HOOKCALL = 0;
161 enum LUA_HOOKRET = 1;
162 enum LUA_HOOKLINE = 2;
163 enum LUA_HOOKCOUNT = 3;
164 enum LUA_HOOKTAILRET = 4;
165 
166 enum LUA_MASKCALL = 1 << LUA_HOOKCALL;
167 enum LUA_MASKRET = 1 << LUA_HOOKRET;
168 enum LUA_MASKLINE = 1 << LUA_HOOKLINE;
169 enum LUA_MASKCOUNT = 1 << LUA_HOOKCOUNT;
170 
171 struct lua_Debug {
172     int event;
173     const(char)* name;
174     const(char)* namewhat;
175     const(char)* what;
176     const(char)* source;
177     size_t srclen;
178     int currentline;
179     int linedefined;
180     int lastlinedefined;
181     ubyte nups;
182     ubyte nparams;
183     char isvararg;
184     char istailcall;
185     ushort ftransfer;
186     ushort ntransfer;
187     char[LUA_IDSIZE] short_src;
188     private void* i_ci;
189 }
190 
191 alias lua_Hook = void function(lua_State*,lua_Debug*) nothrow;
192 
193 // lualib.h
194 enum LUA_VERSUFFIX = "_" ~ LUA_VERSION_MAJOR ~ "_" ~ LUA_VERSION_MINOR;
195 enum LUA_COLIBNAME = "coroutine";
196 enum LUA_TABLIBNAME = "table";
197 enum LUA_IOLIBNAME = "io";
198 enum LUA_OSLIBNAME = "os";
199 enum LUA_STRLIBNAME = "string";
200 enum LUA_UTF8LIBNAME = "utf8";
201 enum LUA_MATHLIBNAME = "math";
202 enum LUA_DBLIBNAME = "debug";
203 enum LUA_LOADLIBNAME = "package";