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