luashim.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  1. /**
  2. * \file luashim.c
  3. * \brief Lua shim for premake binary modules.
  4. * \author Copyright (c) 2017 Tom van Dijck and the Premake project
  5. */
  6. #include "luashim.h"
  7. #include <assert.h>
  8. #include "lstate.h"
  9. static const LuaFunctionTable_t* g_shimTable;
  10. void luaL_register(lua_State *L, const char *libname, const luaL_Reg *l)
  11. {
  12. assert(g_shimTable != NULL);
  13. g_shimTable->shimL_register(L, libname, l);
  14. }
  15. lua_State* lua_newstate(lua_Alloc f, void* ud)
  16. {
  17. assert(g_shimTable != NULL);
  18. return g_shimTable->shim_newstate(f, ud);
  19. }
  20. void lua_close(lua_State* L)
  21. {
  22. assert(g_shimTable != NULL);
  23. g_shimTable->shim_close(L);
  24. }
  25. lua_State* lua_newthread(lua_State* L)
  26. {
  27. assert(g_shimTable != NULL);
  28. return g_shimTable->shim_newthread(L);
  29. }
  30. lua_CFunction lua_atpanic(lua_State* L, lua_CFunction panicf)
  31. {
  32. assert(g_shimTable != NULL);
  33. return g_shimTable->shim_atpanic(L, panicf);
  34. }
  35. const lua_Number* lua_version(lua_State* L)
  36. {
  37. assert(g_shimTable != NULL);
  38. return g_shimTable->shim_version(L);
  39. }
  40. int lua_absindex(lua_State* L, int idx)
  41. {
  42. assert(g_shimTable != NULL);
  43. return g_shimTable->shim_absindex(L, idx);
  44. }
  45. int lua_gettop(lua_State* L)
  46. {
  47. assert(g_shimTable != NULL);
  48. return g_shimTable->shim_gettop(L);
  49. }
  50. void lua_settop(lua_State* L, int idx)
  51. {
  52. assert(g_shimTable != NULL);
  53. g_shimTable->shim_settop(L, idx);
  54. }
  55. void lua_pushvalue(lua_State* L, int idx)
  56. {
  57. assert(g_shimTable != NULL);
  58. g_shimTable->shim_pushvalue(L, idx);
  59. }
  60. void lua_rotate(lua_State* L, int idx, int n)
  61. {
  62. assert(g_shimTable != NULL);
  63. g_shimTable->shim_rotate(L, idx, n);
  64. }
  65. void lua_copy(lua_State* L, int fromidx, int toidx)
  66. {
  67. assert(g_shimTable != NULL);
  68. g_shimTable->shim_copy(L, fromidx, toidx);
  69. }
  70. int lua_checkstack(lua_State* L, int n)
  71. {
  72. assert(g_shimTable != NULL);
  73. return g_shimTable->shim_checkstack(L, n);
  74. }
  75. void lua_xmove(lua_State* from, lua_State* to, int n)
  76. {
  77. assert(g_shimTable != NULL);
  78. g_shimTable->shim_xmove(from, to, n);
  79. }
  80. int lua_isnumber(lua_State* L, int idx)
  81. {
  82. assert(g_shimTable != NULL);
  83. return g_shimTable->shim_isnumber(L, idx);
  84. }
  85. int lua_isstring(lua_State* L, int idx)
  86. {
  87. assert(g_shimTable != NULL);
  88. return g_shimTable->shim_isstring(L, idx);
  89. }
  90. int lua_iscfunction(lua_State* L, int idx)
  91. {
  92. assert(g_shimTable != NULL);
  93. return g_shimTable->shim_iscfunction(L, idx);
  94. }
  95. int lua_isinteger(lua_State* L, int idx)
  96. {
  97. assert(g_shimTable != NULL);
  98. return g_shimTable->shim_isinteger(L, idx);
  99. }
  100. int lua_isuserdata(lua_State* L, int idx)
  101. {
  102. assert(g_shimTable != NULL);
  103. return g_shimTable->shim_isuserdata(L, idx);
  104. }
  105. int lua_type(lua_State* L, int idx)
  106. {
  107. assert(g_shimTable != NULL);
  108. return g_shimTable->shim_type(L, idx);
  109. }
  110. const char* lua_typename(lua_State* L, int tp)
  111. {
  112. assert(g_shimTable != NULL);
  113. return g_shimTable->shim_typename(L, tp);
  114. }
  115. lua_Number lua_tonumberx(lua_State* L, int idx, int* isnum)
  116. {
  117. assert(g_shimTable != NULL);
  118. return g_shimTable->shim_tonumberx(L, idx, isnum);
  119. }
  120. lua_Integer lua_tointegerx(lua_State* L, int idx, int* isnum)
  121. {
  122. assert(g_shimTable != NULL);
  123. return g_shimTable->shim_tointegerx(L, idx, isnum);
  124. }
  125. int lua_toboolean(lua_State* L, int idx)
  126. {
  127. assert(g_shimTable != NULL);
  128. return g_shimTable->shim_toboolean(L, idx);
  129. }
  130. const char* lua_tolstring(lua_State* L, int idx, size_t* len)
  131. {
  132. assert(g_shimTable != NULL);
  133. return g_shimTable->shim_tolstring(L, idx, len);
  134. }
  135. size_t lua_rawlen(lua_State* L, int idx)
  136. {
  137. assert(g_shimTable != NULL);
  138. return g_shimTable->shim_rawlen(L, idx);
  139. }
  140. lua_CFunction lua_tocfunction(lua_State* L, int idx)
  141. {
  142. assert(g_shimTable != NULL);
  143. return g_shimTable->shim_tocfunction(L, idx);
  144. }
  145. void* lua_touserdata(lua_State* L, int idx)
  146. {
  147. assert(g_shimTable != NULL);
  148. return g_shimTable->shim_touserdata(L, idx);
  149. }
  150. lua_State* lua_tothread(lua_State* L, int idx)
  151. {
  152. assert(g_shimTable != NULL);
  153. return g_shimTable->shim_tothread(L, idx);
  154. }
  155. const void* lua_topointer(lua_State* L, int idx)
  156. {
  157. assert(g_shimTable != NULL);
  158. return g_shimTable->shim_topointer(L, idx);
  159. }
  160. void lua_arith(lua_State* L, int op)
  161. {
  162. assert(g_shimTable != NULL);
  163. g_shimTable->shim_arith(L, op);
  164. }
  165. int lua_rawequal(lua_State* L, int idx1, int idx2)
  166. {
  167. assert(g_shimTable != NULL);
  168. return g_shimTable->shim_rawequal(L, idx1, idx2);
  169. }
  170. int lua_compare(lua_State* L, int idx1, int idx2, int op)
  171. {
  172. assert(g_shimTable != NULL);
  173. return g_shimTable->shim_compare(L, idx1, idx2, op);
  174. }
  175. void lua_pushnil(lua_State* L)
  176. {
  177. assert(g_shimTable != NULL);
  178. g_shimTable->shim_pushnil(L);
  179. }
  180. void lua_pushnumber(lua_State* L, lua_Number n)
  181. {
  182. assert(g_shimTable != NULL);
  183. g_shimTable->shim_pushnumber(L, n);
  184. }
  185. void lua_pushinteger(lua_State* L, lua_Integer n)
  186. {
  187. assert(g_shimTable != NULL);
  188. g_shimTable->shim_pushinteger(L, n);
  189. }
  190. const char* lua_pushlstring(lua_State* L, const char* s, size_t len)
  191. {
  192. assert(g_shimTable != NULL);
  193. return g_shimTable->shim_pushlstring(L, s, len);
  194. }
  195. const char* lua_pushstring(lua_State* L, const char* s)
  196. {
  197. assert(g_shimTable != NULL);
  198. return g_shimTable->shim_pushstring(L, s);
  199. }
  200. const char* lua_pushvfstring(lua_State* L, const char* fmt, va_list argp)
  201. {
  202. assert(g_shimTable != NULL);
  203. return g_shimTable->shim_pushvfstring(L, fmt, argp);
  204. }
  205. const char* lua_pushfstring(lua_State* L, const char* fmt, ...)
  206. {
  207. const char* ret;
  208. va_list argp;
  209. va_start(argp, fmt);
  210. ret = lua_pushvfstring(L, fmt, argp);
  211. va_end(argp);
  212. return ret;
  213. }
  214. void lua_pushcclosure(lua_State* L, lua_CFunction fn, int n)
  215. {
  216. assert(g_shimTable != NULL);
  217. g_shimTable->shim_pushcclosure(L, fn, n);
  218. }
  219. void lua_pushboolean(lua_State* L, int b)
  220. {
  221. assert(g_shimTable != NULL);
  222. g_shimTable->shim_pushboolean(L, b);
  223. }
  224. void lua_pushlightuserdata(lua_State* L, void* p)
  225. {
  226. assert(g_shimTable != NULL);
  227. g_shimTable->shim_pushlightuserdata(L, p);
  228. }
  229. int lua_pushthread(lua_State* L)
  230. {
  231. assert(g_shimTable != NULL);
  232. return g_shimTable->shim_pushthread(L);
  233. }
  234. int lua_getglobal(lua_State* L, const char* name)
  235. {
  236. assert(g_shimTable != NULL);
  237. return g_shimTable->shim_getglobal(L, name);
  238. }
  239. int lua_gettable(lua_State* L, int idx)
  240. {
  241. assert(g_shimTable != NULL);
  242. return g_shimTable->shim_gettable(L, idx);
  243. }
  244. int lua_getfield(lua_State* L, int idx, const char* k)
  245. {
  246. assert(g_shimTable != NULL);
  247. return g_shimTable->shim_getfield(L, idx, k);
  248. }
  249. int lua_geti(lua_State* L, int idx, lua_Integer n)
  250. {
  251. assert(g_shimTable != NULL);
  252. return g_shimTable->shim_geti(L, idx, n);
  253. }
  254. int lua_rawget(lua_State* L, int idx)
  255. {
  256. assert(g_shimTable != NULL);
  257. return g_shimTable->shim_rawget(L, idx);
  258. }
  259. int lua_rawgeti(lua_State* L, int idx, lua_Integer n)
  260. {
  261. assert(g_shimTable != NULL);
  262. return g_shimTable->shim_rawgeti(L, idx, n);
  263. }
  264. int lua_rawgetp(lua_State* L, int idx, const void* p)
  265. {
  266. assert(g_shimTable != NULL);
  267. return g_shimTable->shim_rawgetp(L, idx, p);
  268. }
  269. void lua_createtable(lua_State* L, int narr, int nrec)
  270. {
  271. assert(g_shimTable != NULL);
  272. g_shimTable->shim_createtable(L, narr, nrec);
  273. }
  274. void* lua_newuserdata(lua_State* L, size_t sz)
  275. {
  276. assert(g_shimTable != NULL);
  277. return g_shimTable->shim_newuserdata(L, sz);
  278. }
  279. int lua_getmetatable(lua_State* L, int objindex)
  280. {
  281. assert(g_shimTable != NULL);
  282. return g_shimTable->shim_getmetatable(L, objindex);
  283. }
  284. int lua_getuservalue(lua_State* L, int idx)
  285. {
  286. assert(g_shimTable != NULL);
  287. return g_shimTable->shim_getuservalue(L, idx);
  288. }
  289. void lua_setglobal(lua_State* L, const char* name)
  290. {
  291. assert(g_shimTable != NULL);
  292. g_shimTable->shim_setglobal(L, name);
  293. }
  294. void lua_settable(lua_State* L, int idx)
  295. {
  296. assert(g_shimTable != NULL);
  297. g_shimTable->shim_settable(L, idx);
  298. }
  299. void lua_setfield(lua_State* L, int idx, const char* k)
  300. {
  301. assert(g_shimTable != NULL);
  302. g_shimTable->shim_setfield(L, idx, k);
  303. }
  304. void lua_seti(lua_State* L, int idx, lua_Integer n)
  305. {
  306. assert(g_shimTable != NULL);
  307. g_shimTable->shim_seti(L, idx, n);
  308. }
  309. void lua_rawset(lua_State* L, int idx)
  310. {
  311. assert(g_shimTable != NULL);
  312. g_shimTable->shim_rawset(L, idx);
  313. }
  314. void lua_rawseti(lua_State* L, int idx, lua_Integer n)
  315. {
  316. assert(g_shimTable != NULL);
  317. g_shimTable->shim_rawseti(L, idx, n);
  318. }
  319. void lua_rawsetp(lua_State* L, int idx, const void* p)
  320. {
  321. assert(g_shimTable != NULL);
  322. g_shimTable->shim_rawsetp(L, idx, p);
  323. }
  324. int lua_setmetatable(lua_State* L, int objindex)
  325. {
  326. assert(g_shimTable != NULL);
  327. return g_shimTable->shim_setmetatable(L, objindex);
  328. }
  329. void lua_setuservalue(lua_State* L, int idx)
  330. {
  331. assert(g_shimTable != NULL);
  332. g_shimTable->shim_setuservalue(L, idx);
  333. }
  334. void lua_callk(lua_State* L, int nargs, int nresults, lua_KContext ctx, lua_KFunction k)
  335. {
  336. assert(g_shimTable != NULL);
  337. g_shimTable->shim_callk(L, nargs, nresults, ctx, k);
  338. }
  339. int lua_pcallk(lua_State* L, int nargs, int nresults, int errfunc, lua_KContext ctx, lua_KFunction k)
  340. {
  341. assert(g_shimTable != NULL);
  342. return g_shimTable->shim_pcallk(L, nargs, nresults, errfunc, ctx, k);
  343. }
  344. int lua_load(lua_State* L, lua_Reader reader, void* dt, const char* chunkname, const char* mode)
  345. {
  346. assert(g_shimTable != NULL);
  347. return g_shimTable->shim_load(L, reader, dt, chunkname, mode);
  348. }
  349. int lua_dump(lua_State* L, lua_Writer writer, void* data, int strip)
  350. {
  351. assert(g_shimTable != NULL);
  352. return g_shimTable->shim_dump(L, writer, data, strip);
  353. }
  354. int lua_yieldk(lua_State* L, int nresults, lua_KContext ctx, lua_KFunction k)
  355. {
  356. assert(g_shimTable != NULL);
  357. return g_shimTable->shim_yieldk(L, nresults, ctx, k);
  358. }
  359. int lua_resume(lua_State* L, lua_State* from, int narg)
  360. {
  361. assert(g_shimTable != NULL);
  362. return g_shimTable->shim_resume(L, from, narg);
  363. }
  364. int lua_status(lua_State* L)
  365. {
  366. assert(g_shimTable != NULL);
  367. return g_shimTable->shim_status(L);
  368. }
  369. int lua_isyieldable(lua_State* L)
  370. {
  371. assert(g_shimTable != NULL);
  372. return g_shimTable->shim_isyieldable(L);
  373. }
  374. int lua_gc(lua_State* L, int what, int data)
  375. {
  376. assert(g_shimTable != NULL);
  377. return g_shimTable->shim_gc(L, what, data);
  378. }
  379. int lua_error(lua_State* L)
  380. {
  381. assert(g_shimTable != NULL);
  382. return g_shimTable->shim_error(L);
  383. }
  384. int lua_next(lua_State* L, int idx)
  385. {
  386. assert(g_shimTable != NULL);
  387. return g_shimTable->shim_next(L, idx);
  388. }
  389. void lua_concat(lua_State* L, int n)
  390. {
  391. assert(g_shimTable != NULL);
  392. g_shimTable->shim_concat(L, n);
  393. }
  394. void lua_len(lua_State* L, int idx)
  395. {
  396. assert(g_shimTable != NULL);
  397. g_shimTable->shim_len(L, idx);
  398. }
  399. size_t lua_stringtonumber(lua_State* L, const char* s)
  400. {
  401. assert(g_shimTable != NULL);
  402. return g_shimTable->shim_stringtonumber(L, s);
  403. }
  404. lua_Alloc lua_getallocf(lua_State* L, void** ud)
  405. {
  406. assert(g_shimTable != NULL);
  407. return g_shimTable->shim_getallocf(L, ud);
  408. }
  409. void lua_setallocf(lua_State* L, lua_Alloc f, void* ud)
  410. {
  411. assert(g_shimTable != NULL);
  412. g_shimTable->shim_setallocf(L, f, ud);
  413. }
  414. int lua_getstack(lua_State* L, int level, lua_Debug* ar)
  415. {
  416. assert(g_shimTable != NULL);
  417. return g_shimTable->shim_getstack(L, level, ar);
  418. }
  419. int lua_getinfo(lua_State* L, const char* what, lua_Debug* ar)
  420. {
  421. assert(g_shimTable != NULL);
  422. return g_shimTable->shim_getinfo(L, what, ar);
  423. }
  424. const char* lua_getlocal(lua_State* L, const lua_Debug* ar, int n)
  425. {
  426. assert(g_shimTable != NULL);
  427. return g_shimTable->shim_getlocal(L, ar, n);
  428. }
  429. const char* lua_setlocal(lua_State* L, const lua_Debug* ar, int n)
  430. {
  431. assert(g_shimTable != NULL);
  432. return g_shimTable->shim_setlocal(L, ar, n);
  433. }
  434. const char* lua_getupvalue(lua_State* L, int funcindex, int n)
  435. {
  436. assert(g_shimTable != NULL);
  437. return g_shimTable->shim_getupvalue(L, funcindex, n);
  438. }
  439. const char* lua_setupvalue(lua_State* L, int funcindex, int n)
  440. {
  441. assert(g_shimTable != NULL);
  442. return g_shimTable->shim_setupvalue(L, funcindex, n);
  443. }
  444. void* lua_upvalueid(lua_State* L, int fidx, int n)
  445. {
  446. assert(g_shimTable != NULL);
  447. return g_shimTable->shim_upvalueid(L, fidx, n);
  448. }
  449. void lua_upvaluejoin(lua_State* L, int fidx1, int n1, int fidx2, int n2)
  450. {
  451. assert(g_shimTable != NULL);
  452. g_shimTable->shim_upvaluejoin(L, fidx1, n1, fidx2, n2);
  453. }
  454. void lua_sethook(lua_State* L, lua_Hook func, int mask, int count)
  455. {
  456. assert(g_shimTable != NULL);
  457. g_shimTable->shim_sethook(L, func, mask, count);
  458. }
  459. lua_Hook lua_gethook(lua_State* L)
  460. {
  461. assert(g_shimTable != NULL);
  462. return g_shimTable->shim_gethook(L);
  463. }
  464. int lua_gethookmask(lua_State* L)
  465. {
  466. assert(g_shimTable != NULL);
  467. return g_shimTable->shim_gethookmask(L);
  468. }
  469. int lua_gethookcount(lua_State* L)
  470. {
  471. assert(g_shimTable != NULL);
  472. return g_shimTable->shim_gethookcount(L);
  473. }
  474. void luaL_checkversion_(lua_State* L, lua_Number ver, size_t sz)
  475. {
  476. assert(g_shimTable != NULL);
  477. g_shimTable->shimL_checkversion_(L, ver, sz);
  478. }
  479. int luaL_getmetafield(lua_State* L, int obj, const char* e)
  480. {
  481. assert(g_shimTable != NULL);
  482. return g_shimTable->shimL_getmetafield(L, obj, e);
  483. }
  484. int luaL_callmeta(lua_State* L, int obj, const char* e)
  485. {
  486. assert(g_shimTable != NULL);
  487. return g_shimTable->shimL_callmeta(L, obj, e);
  488. }
  489. const char* luaL_tolstring(lua_State* L, int idx, size_t* len)
  490. {
  491. assert(g_shimTable != NULL);
  492. return g_shimTable->shimL_tolstring(L, idx, len);
  493. }
  494. int luaL_argerror(lua_State* L, int arg, const char* extramsg)
  495. {
  496. assert(g_shimTable != NULL);
  497. return g_shimTable->shimL_argerror(L, arg, extramsg);
  498. }
  499. const char* luaL_checklstring(lua_State* L, int arg, size_t* l)
  500. {
  501. assert(g_shimTable != NULL);
  502. return g_shimTable->shimL_checklstring(L, arg, l);
  503. }
  504. const char* luaL_optlstring(lua_State* L, int arg, const char* def, size_t* l)
  505. {
  506. assert(g_shimTable != NULL);
  507. return g_shimTable->shimL_optlstring(L, arg, def, l);
  508. }
  509. lua_Number luaL_checknumber(lua_State* L, int arg)
  510. {
  511. assert(g_shimTable != NULL);
  512. return g_shimTable->shimL_checknumber(L, arg);
  513. }
  514. lua_Number luaL_optnumber(lua_State* L, int arg, lua_Number def)
  515. {
  516. assert(g_shimTable != NULL);
  517. return g_shimTable->shimL_optnumber(L, arg, def);
  518. }
  519. lua_Integer luaL_checkinteger(lua_State* L, int arg)
  520. {
  521. assert(g_shimTable != NULL);
  522. return g_shimTable->shimL_checkinteger(L, arg);
  523. }
  524. lua_Integer luaL_optinteger(lua_State* L, int arg, lua_Integer def)
  525. {
  526. assert(g_shimTable != NULL);
  527. return g_shimTable->shimL_optinteger(L, arg, def);
  528. }
  529. void luaL_checkstack(lua_State* L, int sz, const char* msg)
  530. {
  531. assert(g_shimTable != NULL);
  532. g_shimTable->shimL_checkstack(L, sz, msg);
  533. }
  534. void luaL_checktype(lua_State* L, int arg, int t)
  535. {
  536. assert(g_shimTable != NULL);
  537. g_shimTable->shimL_checktype(L, arg, t);
  538. }
  539. void luaL_checkany(lua_State* L, int arg)
  540. {
  541. assert(g_shimTable != NULL);
  542. g_shimTable->shimL_checkany(L, arg);
  543. }
  544. int luaL_newmetatable(lua_State* L, const char* tname)
  545. {
  546. assert(g_shimTable != NULL);
  547. return g_shimTable->shimL_newmetatable(L, tname);
  548. }
  549. void luaL_setmetatable(lua_State* L, const char* tname)
  550. {
  551. assert(g_shimTable != NULL);
  552. g_shimTable->shimL_setmetatable(L, tname);
  553. }
  554. void* luaL_testudata(lua_State* L, int ud, const char* tname)
  555. {
  556. assert(g_shimTable != NULL);
  557. return g_shimTable->shimL_testudata(L, ud, tname);
  558. }
  559. void* luaL_checkudata(lua_State* L, int ud, const char* tname)
  560. {
  561. assert(g_shimTable != NULL);
  562. return g_shimTable->shimL_checkudata(L, ud, tname);
  563. }
  564. void luaL_where(lua_State* L, int lvl)
  565. {
  566. assert(g_shimTable != NULL);
  567. g_shimTable->shimL_where(L, lvl);
  568. }
  569. int luaL_error(lua_State* L, const char* fmt, ...)
  570. {
  571. va_list argp;
  572. va_start(argp, fmt);
  573. luaL_where(L, 1);
  574. lua_pushvfstring(L, fmt, argp);
  575. va_end(argp);
  576. lua_concat(L, 2);
  577. return lua_error(L);
  578. }
  579. int luaL_checkoption(lua_State* L, int arg, const char* def, const char* const lst[])
  580. {
  581. assert(g_shimTable != NULL);
  582. return g_shimTable->shimL_checkoption(L, arg, def, lst);
  583. }
  584. int luaL_fileresult(lua_State* L, int stat, const char* fname)
  585. {
  586. assert(g_shimTable != NULL);
  587. return g_shimTable->shimL_fileresult(L, stat, fname);
  588. }
  589. int luaL_execresult(lua_State* L, int stat)
  590. {
  591. assert(g_shimTable != NULL);
  592. return g_shimTable->shimL_execresult(L, stat);
  593. }
  594. int luaL_ref(lua_State* L, int t)
  595. {
  596. assert(g_shimTable != NULL);
  597. return g_shimTable->shimL_ref(L, t);
  598. }
  599. void luaL_unref(lua_State* L, int t, int ref)
  600. {
  601. assert(g_shimTable != NULL);
  602. g_shimTable->shimL_unref(L, t, ref);
  603. }
  604. int luaL_loadfilex(lua_State* L, const char* filename, const char* mode)
  605. {
  606. assert(g_shimTable != NULL);
  607. return g_shimTable->shimL_loadfilex(L, filename, mode);
  608. }
  609. int luaL_loadbufferx(lua_State* L, const char* buff, size_t sz, const char* name, const char* mode)
  610. {
  611. assert(g_shimTable != NULL);
  612. return g_shimTable->shimL_loadbufferx(L, buff, sz, name, mode);
  613. }
  614. int luaL_loadstring(lua_State* L, const char* s)
  615. {
  616. assert(g_shimTable != NULL);
  617. return g_shimTable->shimL_loadstring(L, s);
  618. }
  619. lua_State* luaL_newstate()
  620. {
  621. assert(g_shimTable != NULL);
  622. return g_shimTable->shimL_newstate();
  623. }
  624. lua_Integer luaL_len(lua_State* L, int idx)
  625. {
  626. assert(g_shimTable != NULL);
  627. return g_shimTable->shimL_len(L, idx);
  628. }
  629. const char* luaL_gsub(lua_State* L, const char* s, const char* p, const char* r)
  630. {
  631. assert(g_shimTable != NULL);
  632. return g_shimTable->shimL_gsub(L, s, p, r);
  633. }
  634. void luaL_setfuncs(lua_State* L, const luaL_Reg* l, int nup)
  635. {
  636. assert(g_shimTable != NULL);
  637. g_shimTable->shimL_setfuncs(L, l, nup);
  638. }
  639. int luaL_getsubtable(lua_State* L, int idx, const char* fname)
  640. {
  641. assert(g_shimTable != NULL);
  642. return g_shimTable->shimL_getsubtable(L, idx, fname);
  643. }
  644. void luaL_traceback(lua_State* L, lua_State* L1, const char* msg, int level)
  645. {
  646. assert(g_shimTable != NULL);
  647. g_shimTable->shimL_traceback(L, L1, msg, level);
  648. }
  649. void luaL_requiref(lua_State* L, const char* modname, lua_CFunction openf, int glb)
  650. {
  651. assert(g_shimTable != NULL);
  652. g_shimTable->shimL_requiref(L, modname, openf, glb);
  653. }
  654. void luaL_buffinit(lua_State* L, luaL_Buffer* B)
  655. {
  656. assert(g_shimTable != NULL);
  657. g_shimTable->shimL_buffinit(L, B);
  658. }
  659. char* luaL_prepbuffsize(luaL_Buffer* B, size_t sz)
  660. {
  661. assert(g_shimTable != NULL);
  662. return g_shimTable->shimL_prepbuffsize(B, sz);
  663. }
  664. void luaL_addlstring(luaL_Buffer* B, const char* s, size_t l)
  665. {
  666. assert(g_shimTable != NULL);
  667. g_shimTable->shimL_addlstring(B, s, l);
  668. }
  669. void luaL_addstring(luaL_Buffer* B, const char* s)
  670. {
  671. assert(g_shimTable != NULL);
  672. g_shimTable->shimL_addstring(B, s);
  673. }
  674. void luaL_addvalue(luaL_Buffer* B)
  675. {
  676. assert(g_shimTable != NULL);
  677. g_shimTable->shimL_addvalue(B);
  678. }
  679. void luaL_pushresult(luaL_Buffer* B)
  680. {
  681. assert(g_shimTable != NULL);
  682. g_shimTable->shimL_pushresult(B);
  683. }
  684. void luaL_pushresultsize(luaL_Buffer* B, size_t sz)
  685. {
  686. assert(g_shimTable != NULL);
  687. g_shimTable->shimL_pushresultsize(B, sz);
  688. }
  689. char* luaL_buffinitsize(lua_State* L, luaL_Buffer* B, size_t sz)
  690. {
  691. assert(g_shimTable != NULL);
  692. return g_shimTable->shimL_buffinitsize(L, B, sz);
  693. }
  694. static const Node* hashpow2(const Table* t, int n) {
  695. int i = lmod(n, sizenode(t));
  696. return &t->node[i];
  697. }
  698. static const Node* findNode(const Table* t, int key) {
  699. const Node* n = hashpow2(t, key);
  700. while (n->i_key.tvk.value_.i != key)
  701. {
  702. int nx = n->i_key.nk.next;
  703. if (nx == 0)
  704. return NULL;
  705. n += nx;
  706. }
  707. return n;
  708. }
  709. void shimInitialize(lua_State* L)
  710. {
  711. lua_lock(L);
  712. // Find the 'SHIM' entry in the registry.
  713. const Table* reg = hvalue(&G(L)->l_registry);
  714. const Node* n = findNode(reg, 0x5348494D); // equal to 'SHIM'
  715. assert(n != NULL);
  716. g_shimTable = (const LuaFunctionTable_t*)n->i_val.value_.p;
  717. assert(g_shimTable != NULL);
  718. lua_unlock(L);
  719. }