Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 12.75 KB | None | 0 0
  1. #ifndef lua_h
  2. #define lua_h
  3.  
  4. #include <stdarg.h>
  5. #include <stddef.h>
  6.  
  7.  
  8. #include "luaconf.h"
  9.  
  10.  
  11. #define LUA_VERSION_MAJOR       "5"
  12. #define LUA_VERSION_MINOR       "2"
  13. #define LUA_VERSION_NUM         502
  14. #define LUA_VERSION_RELEASE     "4"
  15.  
  16. #define LUA_VERSION     "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
  17. #define LUA_RELEASE     LUA_VERSION "." LUA_VERSION_RELEASE
  18. #define LUA_COPYRIGHT   LUA_RELEASE "  Copyright (C) 1994-2015 Lua.org, PUC-Rio"
  19. #define LUA_AUTHORS     "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
  20.  
  21.  
  22. /* mark for precompiled code ('<esc>Lua') */
  23. #define LUA_SIGNATURE   "\033Lua"
  24.  
  25. /* option for multiple returns in 'lua_pcall' and 'lua_call' */
  26. #define LUA_MULTRET     (-1)
  27.  
  28.  
  29. /*
  30. ** pseudo-indices
  31. */
  32. #define LUA_REGISTRYINDEX       LUAI_FIRSTPSEUDOIDX
  33. #define lua_upvalueindex(i)     (LUA_REGISTRYINDEX - (i))
  34.  
  35.  
  36. /* thread status */
  37. #define LUA_OK          0
  38. #define LUA_YIELD       1
  39. #define LUA_ERRRUN      2
  40. #define LUA_ERRSYNTAX   3
  41. #define LUA_ERRMEM      4
  42. #define LUA_ERRGCMM     5
  43. #define LUA_ERRERR      6
  44.  
  45.  
  46. typedef struct lua_State lua_State;
  47.  
  48. typedef int (*lua_CFunction) (lua_State *L);
  49.  
  50.  
  51. /*
  52. ** functions that read/write blocks when loading/dumping Lua chunks
  53. */
  54. typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
  55.  
  56. typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);
  57.  
  58.  
  59. /*
  60. ** prototype for memory-allocation functions
  61. */
  62. typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
  63.  
  64.  
  65. /*
  66. ** basic types
  67. */
  68. #define LUA_TNONE               (-1)
  69.  
  70. #define LUA_TNIL                0
  71. #define LUA_TBOOLEAN            1
  72. #define LUA_TLIGHTUSERDATA      2
  73. #define LUA_TNUMBER             3
  74. #define LUA_TSTRING             4
  75. #define LUA_TTABLE              5
  76. #define LUA_TFUNCTION           6
  77. #define LUA_TUSERDATA           7
  78. #define LUA_TTHREAD             8
  79.  
  80. #define LUA_NUMTAGS             9
  81.  
  82.  
  83.  
  84. /* minimum Lua stack available to a C function */
  85. #define LUA_MINSTACK    20
  86.  
  87.  
  88. /* predefined values in the registry */
  89. #define LUA_RIDX_MAINTHREAD     1
  90. #define LUA_RIDX_GLOBALS        2
  91. #define LUA_RIDX_LAST           LUA_RIDX_GLOBALS
  92.  
  93.  
  94. /* type of numbers in Lua */
  95. typedef LUA_NUMBER lua_Number;
  96.  
  97.  
  98. /* type for integer functions */
  99. typedef LUA_INTEGER lua_Integer;
  100.  
  101. /* unsigned integer type */
  102. typedef LUA_UNSIGNED lua_Unsigned;
  103.  
  104.  
  105.  
  106. /*
  107. ** generic extra include file
  108. */
  109. #if defined(LUA_USER_H)
  110. #include LUA_USER_H
  111. #endif
  112.  
  113.  
  114. /*
  115. ** RCS ident string
  116. */
  117. extern const char lua_ident[];
  118.  
  119.  
  120. /*
  121. ** state manipulation
  122. */
  123. LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
  124. LUA_API void       (lua_close) (lua_State *L);
  125. LUA_API lua_State *(lua_newthread) (lua_State *L);
  126.  
  127. LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
  128.  
  129.  
  130. LUA_API const lua_Number *(lua_version) (lua_State *L);
  131.  
  132.  
  133. /*
  134. ** basic stack manipulation
  135. */
  136. LUA_API int   (lua_absindex) (lua_State *L, int idx);
  137. LUA_API int   (lua_gettop) (lua_State *L);
  138. LUA_API void  (lua_settop) (lua_State *L, int idx);
  139. LUA_API void  (lua_pushvalue) (lua_State *L, int idx);
  140. LUA_API void  (lua_remove) (lua_State *L, int idx);
  141. LUA_API void  (lua_insert) (lua_State *L, int idx);
  142. LUA_API void  (lua_replace) (lua_State *L, int idx);
  143. LUA_API void  (lua_copy) (lua_State *L, int fromidx, int toidx);
  144. LUA_API int   (lua_checkstack) (lua_State *L, int sz);
  145.  
  146. LUA_API void  (lua_xmove) (lua_State *from, lua_State *to, int n);
  147.  
  148.  
  149. /*
  150. ** access functions (stack -> C)
  151. */
  152.  
  153. LUA_API int             (lua_isnumber) (lua_State *L, int idx);
  154. LUA_API int             (lua_isstring) (lua_State *L, int idx);
  155. LUA_API int             (lua_iscfunction) (lua_State *L, int idx);
  156. LUA_API int             (lua_isuserdata) (lua_State *L, int idx);
  157. LUA_API int             (lua_type) (lua_State *L, int idx);
  158. LUA_API const char     *(lua_typename) (lua_State *L, int tp);
  159.  
  160. LUA_API lua_Number      (lua_tonumberx) (lua_State *L, int idx, int *isnum);
  161. LUA_API lua_Integer     (lua_tointegerx) (lua_State *L, int idx, int *isnum);
  162. LUA_API lua_Unsigned    (lua_tounsignedx) (lua_State *L, int idx, int *isnum);
  163. LUA_API int             (lua_toboolean) (lua_State *L, int idx);
  164. LUA_API const char     *(lua_tolstring) (lua_State *L, int idx, size_t *len);
  165. LUA_API size_t          (lua_rawlen) (lua_State *L, int idx);
  166. LUA_API lua_CFunction   (lua_tocfunction) (lua_State *L, int idx);
  167. LUA_API void           *(lua_touserdata) (lua_State *L, int idx);
  168. LUA_API lua_State      *(lua_tothread) (lua_State *L, int idx);
  169. LUA_API const void     *(lua_topointer) (lua_State *L, int idx);
  170.  
  171.  
  172. /*
  173. ** Comparison and arithmetic functions
  174. */
  175.  
  176. #define LUA_OPADD       0       /* ORDER TM */
  177. #define LUA_OPSUB       1
  178. #define LUA_OPMUL       2
  179. #define LUA_OPDIV       3
  180. #define LUA_OPMOD       4
  181. #define LUA_OPPOW       5
  182. #define LUA_OPUNM       6
  183.  
  184. LUA_API void  (lua_arith) (lua_State *L, int op);
  185.  
  186. #define LUA_OPEQ        0
  187. #define LUA_OPLT        1
  188. #define LUA_OPLE        2
  189.  
  190. LUA_API int   (lua_rawequal) (lua_State *L, int idx1, int idx2);
  191. LUA_API int   (lua_compare) (lua_State *L, int idx1, int idx2, int op);
  192.  
  193.  
  194. /*
  195. ** push functions (C -> stack)
  196. */
  197. LUA_API void        (lua_pushnil) (lua_State *L);
  198. LUA_API void        (lua_pushnumber) (lua_State *L, lua_Number n);
  199. LUA_API void        (lua_pushinteger) (lua_State *L, lua_Integer n);
  200. LUA_API void        (lua_pushunsigned) (lua_State *L, lua_Unsigned n);
  201. LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t l);
  202. LUA_API const char *(lua_pushstring) (lua_State *L, const char *s);
  203. LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
  204.                                                       va_list argp);
  205. LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
  206. LUA_API void  (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
  207. LUA_API void  (lua_pushboolean) (lua_State *L, int b);
  208. LUA_API void  (lua_pushlightuserdata) (lua_State *L, void *p);
  209. LUA_API int   (lua_pushthread) (lua_State *L);
  210.  
  211.  
  212. /*
  213. ** get functions (Lua -> stack)
  214. */
  215. LUA_API void  (lua_getglobal) (lua_State *L, const char *var);
  216. LUA_API void  (lua_gettable) (lua_State *L, int idx);
  217. LUA_API void  (lua_getfield) (lua_State *L, int idx, const char *k);
  218. LUA_API void  (lua_rawget) (lua_State *L, int idx);
  219. LUA_API void  (lua_rawgeti) (lua_State *L, int idx, int n);
  220. LUA_API void  (lua_rawgetp) (lua_State *L, int idx, const void *p);
  221. LUA_API void  (lua_createtable) (lua_State *L, int narr, int nrec);
  222. LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
  223. LUA_API int   (lua_getmetatable) (lua_State *L, int objindex);
  224. LUA_API void  (lua_getuservalue) (lua_State *L, int idx);
  225.  
  226.  
  227. /*
  228. ** set functions (stack -> Lua)
  229. */
  230. LUA_API void  (lua_setglobal) (lua_State *L, const char *var);
  231. LUA_API void  (lua_settable) (lua_State *L, int idx);
  232. LUA_API void  (lua_setfield) (lua_State *L, int idx, const char *k);
  233. LUA_API void  (lua_rawset) (lua_State *L, int idx);
  234. LUA_API void  (lua_rawseti) (lua_State *L, int idx, int n);
  235. LUA_API void  (lua_rawsetp) (lua_State *L, int idx, const void *p);
  236. LUA_API int   (lua_setmetatable) (lua_State *L, int objindex);
  237. LUA_API void  (lua_setuservalue) (lua_State *L, int idx);
  238.  
  239.  
  240. /*
  241. ** 'load' and 'call' functions (load and run Lua code)
  242. */
  243. LUA_API void  (lua_callk) (lua_State *L, int nargs, int nresults, int ctx,
  244.                            lua_CFunction k);
  245. #define lua_call(L,n,r)         lua_callk(L, (n), (r), 0, NULL)
  246.  
  247. LUA_API int   (lua_getctx) (lua_State *L, int *ctx);
  248.  
  249. LUA_API int   (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
  250.                             int ctx, lua_CFunction k);
  251. #define lua_pcall(L,n,r,f)      lua_pcallk(L, (n), (r), (f), 0, NULL)
  252.  
  253. LUA_API int   (lua_load) (lua_State *L, lua_Reader reader, void *dt,
  254.                                         const char *chunkname,
  255.                                         const char *mode);
  256.  
  257. LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);
  258.  
  259.  
  260. /*
  261. ** coroutine functions
  262. */
  263. LUA_API int  (lua_yieldk) (lua_State *L, int nresults, int ctx,
  264.                            lua_CFunction k);
  265. #define lua_yield(L,n)          lua_yieldk(L, (n), 0, NULL)
  266. LUA_API int  (lua_resume) (lua_State *L, lua_State *from, int narg);
  267. LUA_API int  (lua_status) (lua_State *L);
  268.  
  269. /*
  270. ** garbage-collection function and options
  271. */
  272.  
  273. #define LUA_GCSTOP              0
  274. #define LUA_GCRESTART           1
  275. #define LUA_GCCOLLECT           2
  276. #define LUA_GCCOUNT             3
  277. #define LUA_GCCOUNTB            4
  278. #define LUA_GCSTEP              5
  279. #define LUA_GCSETPAUSE          6
  280. #define LUA_GCSETSTEPMUL        7
  281. #define LUA_GCSETMAJORINC       8
  282. #define LUA_GCISRUNNING         9
  283. #define LUA_GCGEN               10
  284. #define LUA_GCINC               11
  285.  
  286. LUA_API int (lua_gc) (lua_State *L, int what, int data);
  287.  
  288.  
  289. /*
  290. ** miscellaneous functions
  291. */
  292.  
  293. LUA_API int   (lua_error) (lua_State *L);
  294.  
  295. LUA_API int   (lua_next) (lua_State *L, int idx);
  296.  
  297. LUA_API void  (lua_concat) (lua_State *L, int n);
  298. LUA_API void  (lua_len)    (lua_State *L, int idx);
  299.  
  300. LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
  301. LUA_API void      (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
  302.  
  303.  
  304.  
  305. /*
  306. ** ===============================================================
  307. ** some useful macros
  308. ** ===============================================================
  309. */
  310.  
  311. #define lua_tonumber(L,i)       lua_tonumberx(L,i,NULL)
  312. #define lua_tointeger(L,i)      lua_tointegerx(L,i,NULL)
  313. #define lua_tounsigned(L,i)     lua_tounsignedx(L,i,NULL)
  314.  
  315. #define lua_pop(L,n)            lua_settop(L, -(n)-1)
  316.  
  317. #define lua_newtable(L)         lua_createtable(L, 0, 0)
  318.  
  319. #define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
  320.  
  321. #define lua_pushcfunction(L,f)  lua_pushcclosure(L, (f), 0)
  322.  
  323. #define lua_isfunction(L,n)     (lua_type(L, (n)) == LUA_TFUNCTION)
  324. #define lua_istable(L,n)        (lua_type(L, (n)) == LUA_TTABLE)
  325. #define lua_islightuserdata(L,n)        (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
  326. #define lua_isnil(L,n)          (lua_type(L, (n)) == LUA_TNIL)
  327. #define lua_isboolean(L,n)      (lua_type(L, (n)) == LUA_TBOOLEAN)
  328. #define lua_isthread(L,n)       (lua_type(L, (n)) == LUA_TTHREAD)
  329. #define lua_isnone(L,n)         (lua_type(L, (n)) == LUA_TNONE)
  330. #define lua_isnoneornil(L, n)   (lua_type(L, (n)) <= 0)
  331.  
  332. #define lua_pushliteral(L, s)   \
  333.         lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
  334.  
  335. #define lua_pushglobaltable(L)  \
  336.         lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS)
  337.  
  338. #define lua_tostring(L,i)       lua_tolstring(L, (i), NULL)
  339.  
  340.  
  341.  
  342. /*
  343. ** {======================================================================
  344. ** Debug API
  345. ** =======================================================================
  346. */
  347.  
  348.  
  349. /*
  350. ** Event codes
  351. */
  352. #define LUA_HOOKCALL    0
  353. #define LUA_HOOKRET     1
  354. #define LUA_HOOKLINE    2
  355. #define LUA_HOOKCOUNT   3
  356. #define LUA_HOOKTAILCALL 4
  357.  
  358.  
  359. /*
  360. ** Event masks
  361. */
  362. #define LUA_MASKCALL    (1 << LUA_HOOKCALL)
  363. #define LUA_MASKRET     (1 << LUA_HOOKRET)
  364. #define LUA_MASKLINE    (1 << LUA_HOOKLINE)
  365. #define LUA_MASKCOUNT   (1 << LUA_HOOKCOUNT)
  366.  
  367. typedef struct lua_Debug lua_Debug;  /* activation record */
  368.  
  369.  
  370. /* Functions to be called by the debugger in specific events */
  371. typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
  372.  
  373.  
  374. LUA_API int (lua_getstack) (lua_State *L, int level, lua_Debug *ar);
  375. LUA_API int (lua_getinfo) (lua_State *L, const char *what, lua_Debug *ar);
  376. LUA_API const char *(lua_getlocal) (lua_State *L, const lua_Debug *ar, int n);
  377. LUA_API const char *(lua_setlocal) (lua_State *L, const lua_Debug *ar, int n);
  378. LUA_API const char *(lua_getupvalue) (lua_State *L, int funcindex, int n);
  379. LUA_API const char *(lua_setupvalue) (lua_State *L, int funcindex, int n);
  380.  
  381. LUA_API void *(lua_upvalueid) (lua_State *L, int fidx, int n);
  382. LUA_API void  (lua_upvaluejoin) (lua_State *L, int fidx1, int n1,
  383.                                                int fidx2, int n2);
  384.  
  385. LUA_API int (lua_sethook) (lua_State *L, lua_Hook func, int mask, int count);
  386. LUA_API lua_Hook (lua_gethook) (lua_State *L);
  387. LUA_API int (lua_gethookmask) (lua_State *L);
  388. LUA_API int (lua_gethookcount) (lua_State *L);
  389.  
  390.  
  391. struct lua_Debug {
  392.   int event;
  393.   const char *name;     /* (n) */
  394.   const char *namewhat; /* (n) 'global', 'local', 'field', 'method' */
  395.   const char *what;     /* (S) 'Lua', 'C', 'main', 'tail' */
  396.   const char *source;   /* (S) */
  397.   int currentline;      /* (l) */
  398.   int linedefined;      /* (S) */
  399.   int lastlinedefined;  /* (S) */
  400.   unsigned char nups;   /* (u) number of upvalues */
  401.   unsigned char nparams;/* (u) number of parameters */
  402.   char isvararg;        /* (u) */
  403.   char istailcall;      /* (t) */
  404.   char short_src[LUA_IDSIZE]; /* (S) */
  405.   /* private part */
  406.   struct CallInfo *i_ci;  /* active function */
  407. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement