package.d 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. // Copyright 2019 - 2021 Michael D. Parker
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. module bindbc.lua.v54;
  6. version(LUA_54):
  7. public import bindbc.lua.v54.types;
  8. version(BindBC_Static) version = BindLua_Static;
  9. version(BindLua_Static) {
  10. public import bindbc.lua.v54.bindstatic;
  11. }
  12. else public import bindbc.lua.v54.binddynamic;
  13. import core.stdc.config : c_long;
  14. // compatibility function aliases
  15. // luaconf.h
  16. alias lua_strlen = lua_rawlen;
  17. alias lua_objlen = lua_rawlen;
  18. // Macros
  19. @nogc nothrow {
  20. // luaconf.h
  21. int lua_equal(lua_State* L, int idx1, int idx2) {
  22. pragma(inline, true)
  23. return lua_compare(L, idx1, idx2, LUA_OPEQ);
  24. }
  25. int lua_lessthan(lua_State* L, int idx1, int idx2) {
  26. pragma(inline, true)
  27. return lua_compare(L, idx1, idx2, LUA_OPLT);
  28. }
  29. // lauxlib.h
  30. void luaL_checkversion(lua_State* L) {
  31. pragma(inline, true)
  32. luaL_checkversion_(L, LUA_VERSION_NUM, LUAL_NUMSIZES);
  33. }
  34. int luaL_loadfile(lua_State* L, const(char)* filename) {
  35. pragma(inline, true)
  36. return luaL_loadfilex(L, filename, null);
  37. }
  38. void luaL_newlibtable(lua_State* L, const(luaL_Reg)[] l) {
  39. pragma(inline, true)
  40. lua_createtable(L, 0, cast(int)l.length - 1);
  41. }
  42. void luaL_newlib(lua_State* L, const(luaL_Reg)[] l) {
  43. pragma(inline, true)
  44. luaL_newlibtable(L, l);
  45. luaL_setfuncs(L, l.ptr, 0);
  46. }
  47. void luaL_argcheck(lua_State* L, bool cond, int arg, const(char)* extramsg) {
  48. pragma(inline, true)
  49. if(!cond) luaL_argerror(L, arg, extramsg);
  50. }
  51. void luaL_argexpected(lua_State* L, bool cond, int arg, const(char)* tname) {
  52. pragma(inline, true)
  53. if(!cond) luaL_typeerror(L, arg, tname);
  54. }
  55. const(char)* luaL_checkstring(lua_State* L, int arg) {
  56. pragma(inline, true)
  57. return luaL_checklstring(L, arg, null);
  58. }
  59. const(char)* luaL_optstring(lua_State* L, int arg, const(char)* d) {
  60. pragma(inline, true)
  61. return luaL_optlstring(L, arg, d, null);
  62. }
  63. const(char)* luaL_typename(lua_State* L, int i) {
  64. pragma(inline, true)
  65. return lua_typename(L, lua_type(L, i));
  66. }
  67. bool luaL_dofile(lua_State* L, const(char)* filename) {
  68. pragma(inline, true)
  69. return luaL_loadfile(L, filename) != 0 || lua_pcall(L, 0, LUA_MULTRET, 0) != 0;
  70. }
  71. bool luaL_dostring(lua_State* L, const(char)* str) {
  72. pragma(inline, true)
  73. return luaL_loadstring(L, str) != 0 || lua_pcall(L, 0, LUA_MULTRET, 0) != 0;
  74. }
  75. void luaL_getmetatable(lua_State* L, const(char)* tname) {
  76. pragma(inline, true)
  77. lua_getfield(L, LUA_REGISTRYINDEX, tname);
  78. }
  79. // TODO: figure out what luaL_opt is supposed to do
  80. int luaL_loadbuffer(lua_State *L, const(char)* buff, size_t sz, const(char)* name) {
  81. pragma(inline, true)
  82. return luaL_loadbufferx(L, buff, sz, name, null);
  83. }
  84. alias luaL_pushfail = lua_pushnil;
  85. size_t luaL_bufflen(luaL_Buffer* B) {
  86. pragma(inline, true)
  87. return B.n;
  88. }
  89. char* luaL_buffaddr(luaL_Buffer* B) {
  90. pragma(inline, true)
  91. return B.b;
  92. }
  93. void luaL_addchar(luaL_Buffer* B, char c) {
  94. pragma(inline, true)
  95. if(B.n < B.size || luaL_prepbuffsize(B, 1)) {
  96. B.b[B.n++] = c;
  97. }
  98. }
  99. void luaL_addsize(luaL_Buffer* B, size_t s) {
  100. pragma(inline, true)
  101. B.n += s;
  102. }
  103. void luaL_buffsub(luaL_Buffer* B, size_t s) {
  104. pragma(inline, true)
  105. B.n -= s;
  106. }
  107. char* luaL_prepbuffer(luaL_Buffer* B) {
  108. pragma(inline, true)
  109. return luaL_prepbuffsize(B, LUAL_BUFFERSIZE);
  110. }
  111. lua_Unsigned luaL_checkunsigned(lua_State* L, int a) {
  112. pragma(inline, true)
  113. return cast(lua_Unsigned)luaL_checkinteger(L, a);
  114. }
  115. lua_Unsigned luaL_optunsigned(lua_State* L, int a, lua_Unsigned d) {
  116. pragma(inline, true)
  117. return cast(lua_Unsigned)luaL_optinteger(L, a, d);
  118. }
  119. int luaL_checkint(lua_State* L, int a) {
  120. pragma(inline, true)
  121. return cast(int)luaL_checkinteger(L, a);
  122. }
  123. int luaL_optint(lua_State* L, int a, int d) {
  124. pragma(inline, true)
  125. return cast(int)luaL_optinteger(L, a, d);
  126. }
  127. c_long luaL_checklong(lua_State* L, int a) {
  128. pragma(inline, true)
  129. return cast(c_long)luaL_checkinteger(L, a);
  130. }
  131. c_long luaL_optlong(lua_State* L, int a, int d) {
  132. pragma(inline, true)
  133. return cast(c_long)luaL_optinteger(L, a, d);
  134. }
  135. // lua.h
  136. int lua_upvalueindex(int i) {
  137. pragma(inline, true)
  138. return LUA_REGISTRYINDEX - i;
  139. }
  140. void lua_call(lua_State* L, int n, int r) {
  141. pragma(inline, true)
  142. lua_callk(L, n, r, 0, null);
  143. }
  144. int lua_pcall(lua_State* L, int n, int r, int f) {
  145. pragma(inline, true)
  146. return lua_pcallk(L, n, r, f, 0, null);
  147. }
  148. int lua_yield(lua_State* L, int n) {
  149. pragma(inline, true)
  150. return lua_yieldk(L, n, 0, null);
  151. }
  152. void* lua_getextraspace(lua_State* L) {
  153. pragma(inline, true)
  154. return cast(void*)((cast(char*)L) - LUA_EXTRASPACE);
  155. }
  156. lua_Number lua_tonumber(lua_State* L, int i) {
  157. pragma(inline, true)
  158. return lua_tonumberx(L, i, null);
  159. }
  160. lua_Integer lua_tointeger(lua_State* L, int i) {
  161. pragma(inline, true)
  162. return lua_tointegerx(L, i, null);
  163. }
  164. void lua_pop(lua_State* L, int n) {
  165. pragma(inline, true)
  166. lua_settop(L, -n - 1);
  167. }
  168. void lua_newtable(lua_State* L) {
  169. pragma(inline, true)
  170. lua_createtable(L, 0, 0);
  171. }
  172. void lua_register(lua_State* L, const(char)* n, lua_CFunction f) {
  173. pragma(inline, true)
  174. lua_pushcfunction(L, f);
  175. lua_setglobal(L, n);
  176. }
  177. void lua_pushcfunction(lua_State* L, lua_CFunction f) {
  178. pragma(inline, true)
  179. lua_pushcclosure(L, f, 0);
  180. }
  181. bool lua_isfunction(lua_State* L, int n) {
  182. pragma(inline, true)
  183. return lua_type(L, n) == LUA_TFUNCTION;
  184. }
  185. bool lua_istable(lua_State* L, int n) {
  186. pragma(inline, true)
  187. return lua_type(L, n) == LUA_TTABLE;
  188. }
  189. bool lua_islightuserdata(lua_State* L, int n) {
  190. pragma(inline, true)
  191. return lua_type(L, n) == LUA_TLIGHTUSERDATA;
  192. }
  193. bool lua_isnil(lua_State* L, int n) {
  194. pragma(inline, true)
  195. return lua_type(L, n) == LUA_TNIL;
  196. }
  197. bool lua_isboolean(lua_State* L, int n) {
  198. pragma(inline, true)
  199. return lua_type(L, n) == LUA_TBOOLEAN;
  200. }
  201. bool lua_isthread(lua_State* L, int n) {
  202. pragma(inline, true)
  203. return lua_type(L, n) == LUA_TTHREAD;
  204. }
  205. bool lua_isnone(lua_State* L, int n) {
  206. pragma(inline, true)
  207. return lua_type(L, n) == LUA_TNONE;
  208. }
  209. bool lua_isnoneornil(lua_State* L, int n) {
  210. pragma(inline, true)
  211. return lua_type(L, n) <= 0;
  212. }
  213. void lua_pushliteral(lua_State* L, const(char)[] s) {
  214. pragma(inline, true)
  215. lua_pushlstring(L, s.ptr, s.length);
  216. }
  217. void lua_pushglobaltable(lua_State* L) {
  218. pragma(inline, true)
  219. lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS);
  220. }
  221. const(char)* lua_tostring(lua_State* L, int i) {
  222. pragma(inline, true)
  223. return lua_tolstring(L, i, null);
  224. }
  225. void lua_insert(lua_State* L, int idx) {
  226. pragma(inline, true)
  227. lua_rotate(L, idx, 1);
  228. }
  229. void lua_remove(lua_State* L, int idx) {
  230. pragma(inline, true)
  231. lua_rotate(L, idx, -1);
  232. lua_pop(L, 1);
  233. }
  234. void lua_replace(lua_State* L, int idx) {
  235. pragma(inline, true)
  236. lua_copy(L, -1, idx);
  237. lua_pop(L, 1);
  238. }
  239. void lua_pushunsigned(lua_State* L, lua_Unsigned n) {
  240. pragma(inline, true)
  241. lua_pushinteger(L, cast(lua_Integer)n);
  242. }
  243. lua_Unsigned lua_tounsignedx(lua_State* L, int i, int* pi) {
  244. pragma(inline, true)
  245. return cast(lua_Unsigned)lua_tointegerx(L, i, pi);
  246. }
  247. lua_Unsigned lua_tounsigned(lua_State* L, int i) {
  248. pragma(inline, true)
  249. return lua_tounsignedx(L, i, null);
  250. }
  251. void* lua_newuserdata(lua_State* L, size_t s) {
  252. pragma(inline, true)
  253. return lua_newuserdatauv(L, s, 1);
  254. }
  255. int lua_getuservalue(lua_State* L, int idx) {
  256. pragma(inline, true)
  257. return lua_getiuservalue(L, idx, 1);
  258. }
  259. int lua_setuservalue(lua_State* L, int idx) {
  260. pragma(inline, true)
  261. return lua_setiuservalue(L, idx, 1);
  262. }
  263. }