Changeset 164


Ignore:
Timestamp:
07/16/13 23:30:12 (12 years ago)
Author:
epyon
Message:
  • lua bindings - much smarter way to implement bindings via macro-datafile trick
  • lua bindings - header supports both lua 5.1 and lua 5.2 depending on passed defines
Location:
trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/lib/lua.hh

    r121 r164  
    3838//#define NV_LUA_SHARED
    3939
    40 #if NV_PLATFORM == NV_WINDOWS
    41 #       define NV_LUA_PATH "lua52.dll"
    42 #elif NV_PLATFORM == NV_APPLE
    43 #       define NV_LUA_PATH "lua5.2.dylib"
    44 #else
    45 #       define NV_LUA_PATH "lua5.2.so"
     40#define NV_LUA_51     0
     41#define NV_LUA_51_JIT 1
     42#define NV_LUA_52     2
     43
     44#ifndef NV_LUA_VERSION
     45#       define NV_LUA_VERSION NV_LUA_52
     46#endif
     47
     48#if NV_LUA_VERSION == NV_LUA_52
     49#       if NV_PLATFORM == NV_WINDOWS
     50#               define NV_LUA_PATH "lua52.dll"
     51#       elif NV_PLATFORM == NV_APPLE
     52#               define NV_LUA_PATH "lua5.2.dylib"
     53#       else
     54#               define NV_LUA_PATH "lua5.2.so"
     55#       endif
     56#elif NV_LUA_VERSION == NV_LUA_51
     57#       if NV_PLATFORM == NV_WINDOWS
     58#               define NV_LUA_PATH "lua51.dll"
     59#       elif NV_PLATFORM == NV_APPLE
     60#               define NV_LUA_PATH "lua5.1.dylib"
     61#       else
     62#               define NV_LUA_PATH "lua5.1.so"
     63#       endif
     64#elif NV_LUA_VERSION == NV_LUA_51_JIT
     65#       if NV_PLATFORM == NV_WINDOWS
     66#               define NV_LUA_PATH "luajit.dll"
     67#       elif NV_PLATFORM == NV_APPLE
     68#               define NV_LUA_PATH "luajit.dylib"
     69#       else
     70#               define NV_LUA_PATH "luajit.so"
     71#       endif
     72#else
     73#       error "Unrecognized NV_LUA_VERSION!"
    4674#endif
    4775
     
    5987#endif
    6088
    61 #if defined(NV_LUA_DYNAMIC)
    62 #       define NV_LUA_FUN( rtype, fname, fparams ) NV_LUA_API rtype (*fname) fparams
    63 #else
    64 #       define NV_LUA_FUN( rtype, fname, fparams ) NV_LUA_API rtype fname fparams
    65 #endif
    66 
    6789/* luaconf.h definitions (only the ones needed in the headers) */
    6890#define LUA_NUMBER   double
     
    7698/* lua.h */
    7799#define LUA_VERSION_MAJOR       "5"
    78 #define LUA_VERSION_MINOR       "2"
    79 #define LUA_VERSION_NUM         502
    80 #define LUA_VERSION_RELEASE     "1"
     100#if NV_LUA_VERSION == NV_LUA_52
     101#       define LUA_VERSION_MINOR        "2"
     102#       define LUA_VERSION_NUM          502
     103#       define LUA_VERSION_RELEASE      "1"
     104#else
     105#       define LUA_VERSION_MAJOR        "5"
     106#       define LUA_VERSION_MINOR        "1"
     107#       define LUA_VERSION_NUM          501
     108#       define LUA_VERSION_RELEASE      "4"
     109#endif
    81110
    82111#define LUA_VERSION     "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
     
    90119#define LUA_REFNIL      (-1)
    91120
    92 #define LUA_REGISTRYINDEX       LUAI_FIRSTPSEUDOIDX
    93 #define lua_upvalueindex(i)     (LUA_REGISTRYINDEX - (i))
     121#if NV_LUA_VERSION == NV_LUA_52
     122#       define LUA_REGISTRYINDEX        LUAI_FIRSTPSEUDOIDX
     123#       define lua_upvalueindex(i)      (LUA_REGISTRYINDEX - (i))
     124#else
     125#       define LUA_REGISTRYINDEX      (-10000)
     126#       define LUA_ENVIRONINDEX       (-10001)
     127#       define LUA_GLOBALSINDEX       (-10002)
     128#       define lua_upvalueindex(i)    (LUA_GLOBALSINDEX-(i))
     129#endif
    94130
    95131#define LUAL_BUFFERSIZE         BUFSIZ
     
    112148  const char *source;   /* (S) */
    113149  int currentline;      /* (l) */
     150#if NV_LUA_VERSION == NV_LUA_52
    114151  int linedefined;      /* (S) */
    115152  int lastlinedefined;  /* (S) */
     
    120157  char short_src[LUA_IDSIZE]; /* (S) */
    121158  struct CallInfo *i_ci;  /* active function */
     159#else
     160  int nups;
     161  int linedefined;      /* (S) */
     162  int lastlinedefined;  /* (S) */
     163  char short_src[LUA_IDSIZE]; /* (S) */
     164  int i_ci;  /* active function */
     165#endif
    122166};
    123167
     
    128172} luaL_Reg;
    129173
     174#if NV_LUA_VERSION == NV_LUA_52
    130175typedef struct luaL_Buffer {
    131   char *b;  /* buffer address */
    132   size_t size;  /* buffer size */
    133   size_t n;  /* number of characters in buffer */
    134   lua_State *L;
    135   char initb[LUAL_BUFFERSIZE];  /* initial buffer */
     176        char *b;  /* buffer address */
     177        size_t size;  /* buffer size */
     178        size_t n;  /* number of characters in buffer */
     179        lua_State *L;
     180        char initb[LUAL_BUFFERSIZE];  /* initial buffer */
    136181} luaL_Buffer;
    137 
     182#else
     183typedef struct luaL_Buffer {
     184        char *p;
     185        int lvl;
     186        lua_State *L;
     187        char initb[LUAL_BUFFERSIZE];
     188} luaL_Buffer;
     189#endif
     190
     191#if NV_LUA_VERSION == NV_LUA_52
    138192typedef struct luaL_Stream {
    139193  FILE *f;  /* stream (NULL for incompletely created streams) */
    140194  lua_CFunction closef;  /* to close stream (NULL for closed streams) */
    141195} luaL_Stream;
     196#endif
    142197
    143198typedef LUA_NUMBER lua_Number;
     
    151206#define LUA_ERRSYNTAX   3
    152207#define LUA_ERRMEM      4
    153 #define LUA_ERRGCMM     5
    154 #define LUA_ERRERR      6
    155 #define LUA_ERRFILE 7
    156 
     208#if NV_LUA_VERSION == NV_LUA_52
     209#       define LUA_ERRGCMM      5
     210#       define LUA_ERRERR       6
     211#       define LUA_ERRFILE  7
     212#else
     213#       define LUA_ERRERR       5
     214#       define LUA_ERRFILE  6
     215#endif
    157216
    158217/* Type codes */
     
    168227#define LUA_TTHREAD                     8
    169228
    170 #define LUA_NUMTAGS                     9
     229#if NV_LUA_VERSION == NV_LUA_52
     230#       define LUA_NUMTAGS                      9
     231#endif
    171232#define LUA_MINSTACK            20
    172233
     234#if NV_LUA_VERSION == NV_LUA_52
    173235/* Pre-defined registers */
    174 #define LUA_RIDX_MAINTHREAD     1
    175 #define LUA_RIDX_GLOBALS        2
    176 #define LUA_RIDX_LAST           LUA_RIDX_GLOBALS
    177 
     236#       define LUA_RIDX_MAINTHREAD      1
     237#       define LUA_RIDX_GLOBALS 2
     238#       define LUA_RIDX_LAST            LUA_RIDX_GLOBALS
     239#endif
     240
     241#if NV_LUA_VERSION == NV_LUA_52
    178242/* OP codes */
    179 #define LUA_OPADD       0
    180 #define LUA_OPSUB       1
    181 #define LUA_OPMUL       2
    182 #define LUA_OPDIV       3
    183 #define LUA_OPMOD       4
    184 #define LUA_OPPOW       5
    185 #define LUA_OPUNM       6
     243#       define LUA_OPADD        0
     244#       define LUA_OPSUB        1
     245#       define LUA_OPMUL        2
     246#       define LUA_OPDIV        3
     247#       define LUA_OPMOD        4
     248#       define LUA_OPPOW        5
     249#       define LUA_OPUNM        6
     250#endif
    186251
    187252/* Compare codes */
    188 #define LUA_OPEQ        0
    189 #define LUA_OPLT        1
    190 #define LUA_OPLE        2
     253#if NV_LUA_VERSION == NV_LUA_52
     254#       define LUA_OPEQ 0
     255#       define LUA_OPLT 1
     256#       define LUA_OPLE 2
     257#endif
    191258
    192259/* Event codes */
     
    199266#define LUA_GCSETPAUSE          6
    200267#define LUA_GCSETSTEPMUL        7
    201 #define LUA_GCSETMAJORINC       8
    202 #define LUA_GCISRUNNING         9
    203 #define LUA_GCGEN                       10
    204 #define LUA_GCINC                       11
     268#if NV_LUA_VERSION == NV_LUA_52
     269#       define LUA_GCSETMAJORINC        8
     270#       define LUA_GCISRUNNING          9
     271#       define LUA_GCGEN                        10
     272#       define LUA_GCINC                        11
     273#endif
    205274
    206275/* Debug event codes */
     
    209278#define LUA_HOOKLINE    2
    210279#define LUA_HOOKCOUNT   3
    211 #define LUA_HOOKTAILCALL 4
     280#if NV_LUA_VERSION == NV_LUA_52
     281#       define LUA_HOOKTAILCALL 4
     282#else
     283#       define LUA_HOOKTAILRET 4
     284#endif
    212285
    213286/* Debug event masks */
     
    223296#define LUA_OSLIBNAME   "os"
    224297#define LUA_STRLIBNAME  "string"
    225 #define LUA_BITLIBNAME  "bit32"
    226298#define LUA_MATHLIBNAME "math"
    227299#define LUA_DBLIBNAME   "debug"
    228300#define LUA_LOADLIBNAME "package"
    229 
    230 /* State manipulation */
    231 NV_LUA_FUN( lua_State *,(lua_newstate),(lua_Alloc f, void *ud) );
    232 NV_LUA_FUN( void       ,(lua_close),(lua_State *L) );
    233 NV_LUA_FUN( lua_State *,(lua_newthread),(lua_State *L) );
    234 NV_LUA_FUN( lua_CFunction,(lua_atpanic),(lua_State *L, lua_CFunction panicf) );
    235 NV_LUA_FUN( const lua_Number *,(lua_version),(lua_State *L) );
    236 
    237 /* Basic stack manipulation */
    238 NV_LUA_FUN( int  ,(lua_absindex),(lua_State *L, int idx) );
    239 NV_LUA_FUN( int  ,(lua_gettop),(lua_State *L) );
    240 NV_LUA_FUN( void ,(lua_settop),(lua_State *L, int idx) );
    241 NV_LUA_FUN( void ,(lua_pushvalue),(lua_State *L, int idx) );
    242 NV_LUA_FUN( void ,(lua_remove),(lua_State *L, int idx) );
    243 NV_LUA_FUN( void ,(lua_insert),(lua_State *L, int idx) );
    244 NV_LUA_FUN( void ,(lua_replace),(lua_State *L, int idx) );
    245 NV_LUA_FUN( void ,(lua_copy),(lua_State *L, int fromidx, int toidx) );
    246 NV_LUA_FUN( int  ,(lua_checkstack),(lua_State *L, int sz) );
    247 NV_LUA_FUN( void ,(lua_xmove),(lua_State *from, lua_State *to, int n) );
    248 
    249 /* Access functions (stack -> C) */
    250 NV_LUA_FUN( int            ,(lua_isnumber),(lua_State *L, int idx) );
    251 NV_LUA_FUN( int            ,(lua_isstring),(lua_State *L, int idx) );
    252 NV_LUA_FUN( int            ,(lua_iscfunction),(lua_State *L, int idx) );
    253 NV_LUA_FUN( int            ,(lua_isuserdata),(lua_State *L, int idx) );
    254 NV_LUA_FUN( int            ,(lua_type),(lua_State *L, int idx) );
    255 NV_LUA_FUN( const char*    ,(lua_typename),(lua_State *L, int tp) );
    256 
    257 NV_LUA_FUN( lua_Number     ,(lua_tonumberx),(lua_State *L, int idx, int *isnum) );
    258 NV_LUA_FUN( lua_Integer    ,(lua_tointegerx),(lua_State *L, int idx, int *isnum) );
    259 NV_LUA_FUN( lua_Unsigned   ,(lua_tounsignedx),(lua_State *L, int idx, int *isnum) );
    260 NV_LUA_FUN( int            ,(lua_toboolean),(lua_State *L, int idx) );
    261 NV_LUA_FUN( const char*    ,(lua_tolstring),(lua_State *L, int idx, size_t *len) );
    262 NV_LUA_FUN( size_t         ,(lua_rawlen),(lua_State *L, int idx) );
    263 NV_LUA_FUN( lua_CFunction  ,(lua_tocfunction),(lua_State *L, int idx) );
    264 NV_LUA_FUN( void*          ,(lua_touserdata),(lua_State *L, int idx) );
    265 NV_LUA_FUN( lua_State*     ,(lua_tothread),(lua_State *L, int idx) );
    266 NV_LUA_FUN( const void*    ,(lua_topointer),(lua_State *L, int idx) );
    267 
    268 /* Comparison and arithmetic functions */
    269 NV_LUA_FUN( void ,(lua_arith),(lua_State *L, int op) );
    270 NV_LUA_FUN( int  ,(lua_rawequal),(lua_State *L, int idx1, int idx2) );
    271 NV_LUA_FUN( int  ,(lua_compare),(lua_State *L, int idx1, int idx2, int op) );
    272 
    273 /* Push functions (C -> stack) */
    274 NV_LUA_FUN( void        ,(lua_pushnil),(lua_State *L) );
    275 NV_LUA_FUN( void        ,(lua_pushnumber),(lua_State *L, lua_Number n) );
    276 NV_LUA_FUN( void        ,(lua_pushinteger),(lua_State *L, lua_Integer n) );
    277 NV_LUA_FUN( void        ,(lua_pushunsigned),(lua_State *L, lua_Unsigned n) );
    278 NV_LUA_FUN( const char* ,(lua_pushlstring),(lua_State *L, const char *s, size_t l) );
    279 NV_LUA_FUN( const char* ,(lua_pushstring),(lua_State *L, const char *s) );
    280 NV_LUA_FUN( const char* ,(lua_pushvfstring),(lua_State *L, const char *fmt,
    281                                                       va_list argp) );
    282 NV_LUA_FUN( const char *,(lua_pushfstring),(lua_State *L, const char *fmt, ...) );
    283 NV_LUA_FUN( void ,(lua_pushcclosure),(lua_State *L, lua_CFunction fn, int n) );
    284 NV_LUA_FUN( void ,(lua_pushboolean),(lua_State *L, int b) );
    285 NV_LUA_FUN( void ,(lua_pushlightuserdata),(lua_State *L, void *p) );
    286 NV_LUA_FUN( int  ,(lua_pushthread),(lua_State *L) );
    287 
    288 /* Get functions (Lua -> stack) */
    289 NV_LUA_FUN( void ,(lua_getglobal),(lua_State *L, const char *var) );
    290 NV_LUA_FUN( void ,(lua_gettable),(lua_State *L, int idx) );
    291 NV_LUA_FUN( void ,(lua_getfield),(lua_State *L, int idx, const char *k) );
    292 NV_LUA_FUN( void ,(lua_rawget),(lua_State *L, int idx) );
    293 NV_LUA_FUN( void ,(lua_rawgeti),(lua_State *L, int idx, int n) );
    294 NV_LUA_FUN( void ,(lua_rawgetp),(lua_State *L, int idx, const void *p) );
    295 NV_LUA_FUN( void ,(lua_createtable),(lua_State *L, int narr, int nrec) );
    296 NV_LUA_FUN( void*,(lua_newuserdata),(lua_State *L, size_t sz) );
    297 NV_LUA_FUN( int  ,(lua_getmetatable),(lua_State *L, int objindex) );
    298 NV_LUA_FUN( void ,(lua_getuservalue),(lua_State *L, int idx) );
    299 
    300 /* Set functions (stack -> Lua) */
    301 NV_LUA_FUN( void ,(lua_setglobal),(lua_State *L, const char *var) );
    302 NV_LUA_FUN( void ,(lua_settable),(lua_State *L, int idx) );
    303 NV_LUA_FUN( void ,(lua_setfield),(lua_State *L, int idx, const char *k) );
    304 NV_LUA_FUN( void ,(lua_rawset),(lua_State *L, int idx) );
    305 NV_LUA_FUN( void ,(lua_rawseti),(lua_State *L, int idx, int n) );
    306 NV_LUA_FUN( void ,(lua_rawsetp),(lua_State *L, int idx, const void *p) );
    307 NV_LUA_FUN( int  ,(lua_setmetatable),(lua_State *L, int objindex) );
    308 NV_LUA_FUN( void ,(lua_setuservalue),(lua_State *L, int idx) );
    309 
    310 /* 'load' and 'call' functions (load and run Lua code) */
    311 NV_LUA_FUN( void ,(lua_callk),(lua_State *L, int nargs, int nresults, int ctx, lua_CFunction k) );
    312 NV_LUA_FUN( int  ,(lua_getctx),(lua_State *L, int *ctx) );
    313 NV_LUA_FUN( int  ,(lua_pcallk),(lua_State *L, int nargs, int nresults, int errfunc, int ctx, lua_CFunction k) );
    314 NV_LUA_FUN( int  ,(lua_load),(lua_State *L, lua_Reader reader, void *dt, const char *chunkname, const char *mode) );
    315 NV_LUA_FUN( int  ,(lua_dump),(lua_State *L, lua_Writer writer, void *data) );
    316 
    317 /* Coroutine functions */
    318 NV_LUA_FUN( int ,(lua_yieldk),(lua_State *L, int nresults, int ctx, lua_CFunction k) );
    319 NV_LUA_FUN( int ,(lua_resume),(lua_State *L, lua_State *from, int narg) );
    320 NV_LUA_FUN( int ,(lua_status),(lua_State *L) );
    321 
    322 /* Garbage-collection function and options */
    323 NV_LUA_FUN( int,(lua_gc),(lua_State *L, int what, int data) );
    324 
    325 /* Miscellaneous functions */
    326 NV_LUA_FUN( int  ,(lua_error),(lua_State *L) );
    327 NV_LUA_FUN( int  ,(lua_next),(lua_State *L, int idx) );
    328 NV_LUA_FUN( void ,(lua_concat),(lua_State *L, int n) );
    329 NV_LUA_FUN( void ,(lua_len)   ,(lua_State *L, int idx) );
    330 NV_LUA_FUN( lua_Alloc,(lua_getallocf),(lua_State *L, void **ud) );
    331 NV_LUA_FUN( void     ,(lua_setallocf),(lua_State *L, lua_Alloc f, void *ud) );
    332 
    333 /* Debug API */
    334 NV_LUA_FUN( int,(lua_getstack),(lua_State *L, int level, lua_Debug *ar) );
    335 NV_LUA_FUN( int,(lua_getinfo),(lua_State *L, const char *what, lua_Debug *ar) );
    336 NV_LUA_FUN( const char *,(lua_getlocal),(lua_State *L, const lua_Debug *ar, int n) );
    337 NV_LUA_FUN( const char *,(lua_setlocal),(lua_State *L, const lua_Debug *ar, int n) );
    338 NV_LUA_FUN( const char *,(lua_getupvalue),(lua_State *L, int funcindex, int n) );
    339 NV_LUA_FUN( const char *,(lua_setupvalue),(lua_State *L, int funcindex, int n) );
    340 NV_LUA_FUN( void *,(lua_upvalueid),(lua_State *L, int fidx, int n) );
    341 NV_LUA_FUN( void  ,(lua_upvaluejoin),(lua_State *L, int fidx1, int n1, int fidx2, int n2) );
    342 NV_LUA_FUN( int,(lua_sethook),(lua_State *L, lua_Hook func, int mask, int count) );
    343 NV_LUA_FUN( lua_Hook,(lua_gethook),(lua_State *L) );
    344 NV_LUA_FUN( int,(lua_gethookmask),(lua_State *L) );
    345 NV_LUA_FUN( int,(lua_gethookcount),(lua_State *L) );
    346 
    347 /* lualib API */
    348 NV_LUA_FUN( int,(luaopen_base),(lua_State *L) );
    349 NV_LUA_FUN( int,(luaopen_coroutine),(lua_State *L) );
    350 NV_LUA_FUN( int,(luaopen_table),(lua_State *L) );
    351 NV_LUA_FUN( int,(luaopen_io),(lua_State *L) );
    352 NV_LUA_FUN( int,(luaopen_os),(lua_State *L) );
    353 NV_LUA_FUN( int,(luaopen_string),(lua_State *L) );
    354 NV_LUA_FUN( int,(luaopen_bit32),(lua_State *L) );
    355 NV_LUA_FUN( int,(luaopen_math),(lua_State *L) );
    356 NV_LUA_FUN( int,(luaopen_debug),(lua_State *L) );
    357 NV_LUA_FUN( int,(luaopen_package),(lua_State *L) );
    358 NV_LUA_FUN( int,(luaL_openlibs),(lua_State *L) );
    359 
    360 /* lauxlib API */
    361 NV_LUA_FUN( void  ,(luaL_checkversion_),(lua_State *L, lua_Number ver) );
    362 NV_LUA_FUN( int ,(luaL_getmetafield),(lua_State *L, int obj, const char *e) );
    363 NV_LUA_FUN( int ,(luaL_callmeta),(lua_State *L, int obj, const char *e) );
    364 NV_LUA_FUN( const char *,(luaL_tolstring),(lua_State *L, int idx, size_t *len) );
    365 NV_LUA_FUN( int ,(luaL_argerror),(lua_State *L, int numarg, const char *extramsg) );
    366 NV_LUA_FUN( const char *,(luaL_checklstring),(lua_State *L, int numArg, size_t *l) );
    367 NV_LUA_FUN( const char *,(luaL_optlstring),(lua_State *L, int numArg, const char *def, size_t *l) );
    368 NV_LUA_FUN( lua_Number ,(luaL_checknumber),(lua_State *L, int numArg) );
    369 NV_LUA_FUN( lua_Number ,(luaL_optnumber),(lua_State *L, int nArg, lua_Number def) );
    370 NV_LUA_FUN( lua_Integer ,(luaL_checkinteger),(lua_State *L, int numArg) );
    371 NV_LUA_FUN( lua_Integer ,(luaL_optinteger),(lua_State *L, int nArg, lua_Integer def) );
    372 NV_LUA_FUN( lua_Unsigned ,(luaL_checkunsigned),(lua_State *L, int numArg) );
    373 NV_LUA_FUN( lua_Unsigned ,(luaL_optunsigned),(lua_State *L, int numArg, lua_Unsigned def) );
    374 NV_LUA_FUN( void ,(luaL_checkstack),(lua_State *L, int sz, const char *msg) );
    375 NV_LUA_FUN( void ,(luaL_checktype),(lua_State *L, int narg, int t) );
    376 NV_LUA_FUN( void ,(luaL_checkany),(lua_State *L, int narg) );
    377 NV_LUA_FUN( int   ,(luaL_newmetatable),(lua_State *L, const char *tname) );
    378 NV_LUA_FUN( void  ,(luaL_setmetatable),(lua_State *L, const char *tname) );
    379 NV_LUA_FUN( void *,(luaL_testudata),(lua_State *L, int ud, const char *tname) );
    380 NV_LUA_FUN( void *,(luaL_checkudata),(lua_State *L, int ud, const char *tname) );
    381 NV_LUA_FUN( void ,(luaL_where),(lua_State *L, int lvl) );
    382 NV_LUA_FUN( int ,(luaL_error),(lua_State *L, const char *fmt, ...) );
    383 NV_LUA_FUN( int ,(luaL_checkoption),(lua_State *L, int narg, const char *def, const char *const lst[]) );
    384 NV_LUA_FUN( int ,(luaL_fileresult),(lua_State *L, int stat, const char *fname) );
    385 NV_LUA_FUN( int ,(luaL_execresult),(lua_State *L, int stat) );
    386 
    387 NV_LUA_FUN( int ,(luaL_ref),(lua_State *L, int t) );
    388 NV_LUA_FUN( void ,(luaL_unref),(lua_State *L, int t, int ref) );
    389 NV_LUA_FUN( int ,(luaL_loadfilex),(lua_State *L, const char *filename, const char *mode) );
    390 NV_LUA_FUN( int ,(luaL_loadbufferx),(lua_State *L, const char *buff, size_t sz, const char *name, const char *mode) );
    391 NV_LUA_FUN( int ,(luaL_loadstring),(lua_State *L, const char *s) );
    392 NV_LUA_FUN( lua_State *,(luaL_newstate), (void) );
    393 NV_LUA_FUN( int ,(luaL_len),(lua_State *L, int idx) );
    394 NV_LUA_FUN( const char *,(luaL_gsub),(lua_State *L, const char *s, const char *p, const char *r) );
    395 NV_LUA_FUN( void ,(luaL_setfuncs),(lua_State *L, const luaL_Reg *l, int nup) );
    396 NV_LUA_FUN( int ,(luaL_getsubtable),(lua_State *L, int idx, const char *fname) );
    397 NV_LUA_FUN( void ,(luaL_traceback),(lua_State *L, lua_State *L1, const char *msg, int level) );
    398 NV_LUA_FUN( void ,(luaL_requiref),(lua_State *L, const char *modname, lua_CFunction openf, int glb) );
     301#if NV_LUA_VERSION == NV_LUA_52
     302#       define LUA_BITLIBNAME   "bit32"
     303#endif
     304
     305#if defined(NV_LUA_DYNAMIC)
     306#       define NV_LUA_FUN( rtype, fname, fparams ) NV_LUA_API rtype (*fname) fparams
     307#else
     308#       define NV_LUA_FUN( rtype, fname, fparams ) NV_LUA_API rtype fname fparams
     309#endif
     310
     311#if NV_LUA_VERSION == NV_LUA_52
     312#       define NV_LUA_FUN_51( rtype, fname, fparams )
     313#       define NV_LUA_FUN_52 NV_LUA_FUN
     314#else
     315#       define NV_LUA_FUN_51 NV_LUA_FUN
     316#       define NV_LUA_FUN_52( rtype, fname, fparams )
     317#endif
     318
     319#include <nv/lib/detail/lua_functions.inc>
    399320
    400321#undef NV_LUA_FUN
     322#undef NV_LUA_FUN_51
     323#undef NV_LUA_FUN_52
    401324
    402325/* Macros */
    403 #define lua_call(L,n,r)         lua_callk(L, (n), (r), 0, NULL)
    404 #define lua_pcall(L,n,r,f)      lua_pcallk(L, (n), (r), (f), 0, NULL)
    405 #define lua_yield(L,n)          lua_yieldk(L, (n), 0, NULL)
    406 #define lua_tonumber(L,i)       lua_tonumberx(L,i,NULL)
    407 #define lua_tointeger(L,i)      lua_tointegerx(L,i,NULL)
    408 #define lua_tounsigned(L,i)     lua_tounsignedx(L,i,NULL)
     326#if NV_LUA_VERSION == NV_LUA_52
     327#       define lua_yield(L,n)           lua_yieldk(L, (n), 0, NULL)
     328#       define lua_call(L,n,r)          lua_callk(L, (n), (r), 0, NULL)
     329#       define lua_pcall(L,n,r,f)       lua_pcallk(L, (n), (r), (f), 0, NULL)
     330#       define lua_tonumber(L,i)        lua_tonumberx(L,i,NULL)
     331#       define lua_tointeger(L,i)       lua_tointegerx(L,i,NULL)
     332#       define lua_tounsigned(L,i)      lua_tounsignedx(L,i,NULL)
     333#endif
    409334#define lua_pop(L,n)            lua_settop(L, -(n)-1)
    410335#define lua_newtable(L)         lua_createtable(L, 0, 0)
     
    420345#define lua_isnoneornil(L, n)   (lua_type(L, (n)) <= 0)
    421346#define lua_pushliteral(L, s)   lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
    422 #define lua_pushglobaltable(L)  lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS)
     347#if NV_LUA_VERSION == NV_LUA_52
     348#       define lua_pushglobaltable(L)  lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS)
     349#else
     350#       define lua_setglobal(L,s)     lua_setfield(L, LUA_GLOBALSINDEX, (s))
     351#       define lua_getglobal(L,s)     lua_getfield(L, LUA_GLOBALSINDEX, (s))
     352#endif
     353
    423354#define lua_tostring(L,i)       lua_tolstring(L, (i), NULL)
    424355
    425356/* Aux lib macros */
    426 #define luaL_checkversion(L)    luaL_checkversion_(L, LUA_VERSION_NUM)
    427 #define luaL_loadfile(L,f)      luaL_loadfilex(L,f,NULL)
    428 #define luaL_newlibtable(L,l)   lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)
    429 #define luaL_newlib(L,l)        (luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
     357#if NV_LUA_VERSION == NV_LUA_52
     358#       define luaL_checkversion(L)     luaL_checkversion_(L, LUA_VERSION_NUM)
     359#       define luaL_loadfile(L,f)       luaL_loadfilex(L,f,NULL)
     360#       define luaL_loadbuffer(L,s,sz,n)        luaL_loadbufferx(L,s,sz,n,NULL)
     361#       define luaL_newlibtable(L,l)    lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)
     362#       define luaL_newlib(L,l) (luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
     363#endif
    430364#define luaL_argcheck(L, cond,numarg,extramsg)  ((void)((cond) || luaL_argerror(L, (numarg), (extramsg))))
    431365#define luaL_checkstring(L,n)   (luaL_checklstring(L, (n), NULL))
     
    440374#define luaL_getmetatable(L,n)  (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
    441375#define luaL_opt(L,f,n,d)       (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
    442 #define luaL_loadbuffer(L,s,sz,n)       luaL_loadbufferx(L,s,sz,n,NULL)
    443 #define luaL_addchar(B,c)  ((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), ((B)->b[(B)->n++] = (c)))
    444 #define luaL_addsize(B,s)       ((B)->n += (s))
    445 #define luaL_prepbuffer(B)      luaL_prepbuffsize(B, LUAL_BUFFERSIZE)
     376#if NV_LUA_VERSION == NV_LUA_52
     377#       define luaL_prepbuffer(B)       luaL_prepbuffsize(B, LUAL_BUFFERSIZE)
     378#       define luaL_addchar(B,c) ((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), ((B)->b[(B)->n++] = (c)))
     379#       define luaL_addsize(B,s)        ((B)->n += (s))
     380#else
     381#       define luaL_addchar(B,c) ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), (*(B)->p++ = (char)(c)))
     382#       define luaL_addsize(B,n)  ((B)->p += (n))
     383#endif
    446384
    447385}
  • trunk/src/lib/lua.cc

    r109 r164  
    1111#include "nv/library.hh"
    1212
    13 /* State manipulation */
    14 lua_State *        (*lua_newstate) (lua_Alloc f, void *ud) = nullptr;
    15 void               (*lua_close) (lua_State *L) = nullptr;
    16 lua_State *        (*lua_newthread) (lua_State *L) = nullptr;
    17 lua_CFunction      (*lua_atpanic) (lua_State *L, lua_CFunction panicf) = nullptr;
    18 const lua_Number * (*lua_version) (lua_State *L) = nullptr;
     13#if NV_LUA_VERSION == NV_LUA_52
     14#       undef luaL_loadfile
     15#       undef luaL_loadbuffer
     16#       undef luaL_prepbuffer
     17#       undef lua_tonumber
     18#       undef lua_tointeger
     19#       undef lua_tounsigned
     20#       undef lua_call
     21#       undef lua_pcall
     22#       undef lua_yield
     23#endif
    1924
    20 /* Basic stack manipulation */
    21 int   (*lua_absindex) (lua_State *L, int idx) = nullptr;
    22 int   (*lua_gettop) (lua_State *L) = nullptr;
    23 void  (*lua_settop) (lua_State *L, int idx) = nullptr;
    24 void  (*lua_pushvalue) (lua_State *L, int idx) = nullptr;
    25 void  (*lua_remove) (lua_State *L, int idx) = nullptr;
    26 void  (*lua_insert) (lua_State *L, int idx) = nullptr;
    27 void  (*lua_replace) (lua_State *L, int idx) = nullptr;
    28 void  (*lua_copy) (lua_State *L, int fromidx, int toidx) = nullptr;
    29 int   (*lua_checkstack) (lua_State *L, int sz) = nullptr;
    30 void  (*lua_xmove) (lua_State *from, lua_State *to, int n) = nullptr;
     25#define NV_LUA_FUN( rtype, fname, fparams ) rtype (*fname) fparams = nullptr;
     26#if NV_LUA_VERSION == NV_LUA_52
     27#       define NV_LUA_FUN_51( rtype, fname, fparams )
     28#       define NV_LUA_FUN_52 NV_LUA_FUN
     29#else
     30#       define NV_LUA_FUN_51 NV_LUA_FUN
     31#       define NV_LUA_FUN_52( rtype, fname, fparams )
     32#endif
    3133
    32 /* Access functions (stack -> C) */
    33 int             (*lua_isnumber) (lua_State *L, int idx) = nullptr;
    34 int             (*lua_isstring) (lua_State *L, int idx) = nullptr;
    35 int             (*lua_iscfunction) (lua_State *L, int idx) = nullptr;
    36 int             (*lua_isuserdata) (lua_State *L, int idx) = nullptr;
    37 int             (*lua_type) (lua_State *L, int idx) = nullptr;
    38 const char*     (*lua_typename) (lua_State *L, int tp) = nullptr;
     34#include <nv/lib/detail/lua_functions.inc>
    3935
    40 lua_Number      (*lua_tonumberx) (lua_State *L, int idx, int *isnum) = nullptr;
    41 lua_Integer     (*lua_tointegerx) (lua_State *L, int idx, int *isnum) = nullptr;
    42 lua_Unsigned    (*lua_tounsignedx) (lua_State *L, int idx, int *isnum) = nullptr;
    43 int             (*lua_toboolean) (lua_State *L, int idx) = nullptr;
    44 const char*     (*lua_tolstring) (lua_State *L, int idx, size_t *len) = nullptr;
    45 size_t          (*lua_rawlen) (lua_State *L, int idx) = nullptr;
    46 lua_CFunction   (*lua_tocfunction) (lua_State *L, int idx) = nullptr;
    47 void*           (*lua_touserdata) (lua_State *L, int idx) = nullptr;
    48 lua_State*      (*lua_tothread) (lua_State *L, int idx) = nullptr;
    49 const void*     (*lua_topointer) (lua_State *L, int idx) = nullptr;
    50 
    51 /* Comparison and arithmetic functions */
    52 void  (*lua_arith) (lua_State *L, int op) = nullptr;
    53 int   (*lua_rawequal) (lua_State *L, int idx1, int idx2) = nullptr;
    54 int   (*lua_compare) (lua_State *L, int idx1, int idx2, int op) = nullptr;
    55 
    56 /* Push functions (C -> stack) */
    57 void         (*lua_pushnil) (lua_State *L) = nullptr;
    58 void         (*lua_pushnumber) (lua_State *L, lua_Number n) = nullptr;
    59 void         (*lua_pushinteger) (lua_State *L, lua_Integer n) = nullptr;
    60 void         (*lua_pushunsigned) (lua_State *L, lua_Unsigned n) = nullptr;
    61 const char*  (*lua_pushlstring) (lua_State *L, const char *s, size_t l) = nullptr;
    62 const char*  (*lua_pushstring) (lua_State *L, const char *s) = nullptr;
    63 const char*  (*lua_pushvfstring) (lua_State *L, const char *fmt,
    64                                                       va_list argp) = nullptr;
    65 const char * (*lua_pushfstring) (lua_State *L, const char *fmt, ...) = nullptr;
    66 void  (*lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n) = nullptr;
    67 void  (*lua_pushboolean) (lua_State *L, int b) = nullptr;
    68 void  (*lua_pushlightuserdata) (lua_State *L, void *p) = nullptr;
    69 int   (*lua_pushthread) (lua_State *L) = nullptr;
    70 
    71 /* Get functions (Lua -> stack) */
    72 void  (*lua_getglobal) (lua_State *L, const char *var) = nullptr;
    73 void  (*lua_gettable) (lua_State *L, int idx) = nullptr;
    74 void  (*lua_getfield) (lua_State *L, int idx, const char *k) = nullptr;
    75 void  (*lua_rawget) (lua_State *L, int idx) = nullptr;
    76 void  (*lua_rawgeti) (lua_State *L, int idx, int n) = nullptr;
    77 void  (*lua_rawgetp) (lua_State *L, int idx, const void *p) = nullptr;
    78 void  (*lua_createtable) (lua_State *L, int narr, int nrec) = nullptr;
    79 void* (*lua_newuserdata) (lua_State *L, size_t sz) = nullptr;
    80 int   (*lua_getmetatable) (lua_State *L, int objindex) = nullptr;
    81 void  (*lua_getuservalue) (lua_State *L, int idx) = nullptr;
    82 
    83 /* Set functions (stack -> Lua) */
    84 void  (*lua_setglobal) (lua_State *L, const char *var) = nullptr;
    85 void  (*lua_settable) (lua_State *L, int idx) = nullptr;
    86 void  (*lua_setfield) (lua_State *L, int idx, const char *k) = nullptr;
    87 void  (*lua_rawset) (lua_State *L, int idx) = nullptr;
    88 void  (*lua_rawseti) (lua_State *L, int idx, int n) = nullptr;
    89 void  (*lua_rawsetp) (lua_State *L, int idx, const void *p) = nullptr;
    90 int   (*lua_setmetatable) (lua_State *L, int objindex) = nullptr;
    91 void  (*lua_setuservalue) (lua_State *L, int idx) = nullptr;
    92 
    93 /* 'load' and 'call' functions (load and run Lua code) */
    94 void  (*lua_callk) (lua_State *L, int nargs, int nresults, int ctx, lua_CFunction k) = nullptr;
    95 int   (*lua_getctx) (lua_State *L, int *ctx) = nullptr;
    96 int   (*lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc, int ctx, lua_CFunction k) = nullptr;
    97 int   (*lua_load) (lua_State *L, lua_Reader reader, void *dt, const char *chunkname, const char *mode) = nullptr;
    98 int   (*lua_dump) (lua_State *L, lua_Writer writer, void *data) = nullptr;
    99 
    100 /* Coroutine functions */
    101 int  (*lua_yieldk) (lua_State *L, int nresults, int ctx, lua_CFunction k) = nullptr;
    102 int  (*lua_resume) (lua_State *L, lua_State *from, int narg) = nullptr;
    103 int  (*lua_status) (lua_State *L) = nullptr;
    104 
    105 /* Garbage-collection function and options */
    106 int (*lua_gc) (lua_State *L, int what, int data) = nullptr;
    107 
    108 /* Miscellaneous functions */
    109 int   (*lua_error) (lua_State *L) = nullptr;
    110 int   (*lua_next) (lua_State *L, int idx) = nullptr;
    111 void  (*lua_concat) (lua_State *L, int n) = nullptr;
    112 void  (*lua_len)    (lua_State *L, int idx) = nullptr;
    113 lua_Alloc (*lua_getallocf) (lua_State *L, void **ud) = nullptr;
    114 void      (*lua_setallocf) (lua_State *L, lua_Alloc f, void *ud) = nullptr;
    115 
    116 /* Debug API */
    117 int (*lua_getstack) (lua_State *L, int level, lua_Debug *ar) = nullptr;
    118 int (*lua_getinfo) (lua_State *L, const char *what, lua_Debug *ar) = nullptr;
    119 const char * (*lua_getlocal) (lua_State *L, const lua_Debug *ar, int n) = nullptr;
    120 const char * (*lua_setlocal) (lua_State *L, const lua_Debug *ar, int n) = nullptr;
    121 const char * (*lua_getupvalue) (lua_State *L, int funcindex, int n) = nullptr;
    122 const char * (*lua_setupvalue) (lua_State *L, int funcindex, int n) = nullptr;
    123 void * (*lua_upvalueid) (lua_State *L, int fidx, int n) = nullptr;
    124 void   (*lua_upvaluejoin) (lua_State *L, int fidx1, int n1, int fidx2, int n2) = nullptr;
    125 int (*lua_sethook) (lua_State *L, lua_Hook func, int mask, int count) = nullptr;
    126 lua_Hook (*lua_gethook) (lua_State *L) = nullptr;
    127 int (*lua_gethookmask) (lua_State *L) = nullptr;
    128 int (*lua_gethookcount) (lua_State *L) = nullptr;
    129 
    130 /* lualib API */
    131 int (*luaopen_base) (lua_State *L) = nullptr;
    132 int (*luaopen_coroutine) (lua_State *L) = nullptr;
    133 int (*luaopen_table) (lua_State *L) = nullptr;
    134 int (*luaopen_io) (lua_State *L) = nullptr;
    135 int (*luaopen_os) (lua_State *L) = nullptr;
    136 int (*luaopen_string) (lua_State *L) = nullptr;
    137 int (*luaopen_bit32) (lua_State *L) = nullptr;
    138 int (*luaopen_math) (lua_State *L) = nullptr;
    139 int (*luaopen_debug) (lua_State *L) = nullptr;
    140 int (*luaopen_package) (lua_State *L) = nullptr;
    141 int (*luaL_openlibs) (lua_State *L) = nullptr;
    142 
    143 /* lauxlib API */
    144 void   (*luaL_checkversion_) (lua_State *L, lua_Number ver) = nullptr;
    145 int  (*luaL_getmetafield) (lua_State *L, int obj, const char *e) = nullptr;
    146 int  (*luaL_callmeta) (lua_State *L, int obj, const char *e) = nullptr;
    147 const char * (*luaL_tolstring) (lua_State *L, int idx, size_t *len) = nullptr;
    148 int  (*luaL_argerror) (lua_State *L, int numarg, const char *extramsg) = nullptr;
    149 const char * (*luaL_checklstring) (lua_State *L, int numArg, size_t *l) = nullptr;
    150 const char * (*luaL_optlstring) (lua_State *L, int numArg, const char *def, size_t *l) = nullptr;
    151 lua_Number  (*luaL_checknumber) (lua_State *L, int numArg) = nullptr;
    152 lua_Number  (*luaL_optnumber) (lua_State *L, int nArg, lua_Number def) = nullptr;
    153 lua_Integer  (*luaL_checkinteger) (lua_State *L, int numArg) = nullptr;
    154 lua_Integer  (*luaL_optinteger) (lua_State *L, int nArg, lua_Integer def) = nullptr;
    155 lua_Unsigned  (*luaL_checkunsigned) (lua_State *L, int numArg) = nullptr;
    156 lua_Unsigned  (*luaL_optunsigned) (lua_State *L, int numArg, lua_Unsigned def) = nullptr;
    157 void  (*luaL_checkstack) (lua_State *L, int sz, const char *msg) = nullptr;
    158 void  (*luaL_checktype) (lua_State *L, int narg, int t) = nullptr;
    159 void  (*luaL_checkany) (lua_State *L, int narg) = nullptr;
    160 int    (*luaL_newmetatable) (lua_State *L, const char *tname) = nullptr;
    161 void   (*luaL_setmetatable) (lua_State *L, const char *tname) = nullptr;
    162 void * (*luaL_testudata) (lua_State *L, int ud, const char *tname) = nullptr;
    163 void * (*luaL_checkudata) (lua_State *L, int ud, const char *tname) = nullptr;
    164 void  (*luaL_where) (lua_State *L, int lvl) = nullptr;
    165 int  (*luaL_error) (lua_State *L, const char *fmt, ...) = nullptr;
    166 int  (*luaL_checkoption) (lua_State *L, int narg, const char *def, const char *const lst[]) = nullptr;
    167 int  (*luaL_fileresult) (lua_State *L, int stat, const char *fname) = nullptr;
    168 int  (*luaL_execresult) (lua_State *L, int stat) = nullptr;
    169 
    170 int  (*luaL_ref) (lua_State *L, int t) = nullptr;
    171 void  (*luaL_unref) (lua_State *L, int t, int ref) = nullptr;
    172 int  (*luaL_loadfilex) (lua_State *L, const char *filename, const char *mode) = nullptr;
    173 int  (*luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz, const char *name, const char *mode) = nullptr;
    174 int  (*luaL_loadstring) (lua_State *L, const char *s) = nullptr;
    175 lua_State * (*luaL_newstate)  (void) = nullptr;
    176 int  (*luaL_len) (lua_State *L, int idx) = nullptr;
    177 const char * (*luaL_gsub) (lua_State *L, const char *s, const char *p, const char *r) = nullptr;
    178 void  (*luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup) = nullptr;
    179 int  (*luaL_getsubtable) (lua_State *L, int idx, const char *fname) = nullptr;
    180 void  (*luaL_traceback) (lua_State *L, lua_State *L1, const char *msg, int level) = nullptr;
    181 void  (*luaL_requiref) (lua_State *L, const char *modname, lua_CFunction openf, int glb) = nullptr;
     36#undef NV_LUA_FUN
     37#undef NV_LUA_FUN_51
     38#undef NV_LUA_FUN_52
    18239
    18340bool nv::load_lua_library( const char* path )
    18441{
    185 #       define NV_LUA_LOAD( symbol ) *(void **) (&symbol) = lua_library.get(#symbol);
    186 
    18742        static nv::library lua_library;
    18843        if ( lua_library.is_open() ) return true;
    18944        lua_library.open( path );
    19045
     46#       define NV_LUA_FUN( rtype, fname, fparams ) *(void **) (&fname) = lua_library.get(#fname);
     47#       if NV_LUA_VERSION == NV_LUA_52
     48#               define NV_LUA_FUN_51( rtype, fname, fparams )
     49#               define NV_LUA_FUN_52 NV_LUA_FUN
     50#       else
     51#               define NV_LUA_FUN_51 NV_LUA_FUN
     52#               define NV_LUA_FUN_52( rtype, fname, fparams )
     53#       endif
    19154
    192 /* State manipulation */
    193         NV_LUA_LOAD(lua_newstate);
    194         NV_LUA_LOAD(lua_close);
    195         NV_LUA_LOAD(lua_newthread);
    196         NV_LUA_LOAD(lua_atpanic);
    197         NV_LUA_LOAD(lua_version);
     55#include <nv/lib/detail/lua_functions.inc>
    19856
    199 /* Basic stack manipulation */
    200         NV_LUA_LOAD(lua_absindex);
    201         NV_LUA_LOAD(lua_gettop);
    202         NV_LUA_LOAD(lua_settop);
    203         NV_LUA_LOAD(lua_pushvalue);
    204         NV_LUA_LOAD(lua_remove);
    205         NV_LUA_LOAD(lua_insert);
    206         NV_LUA_LOAD(lua_replace);
    207         NV_LUA_LOAD(lua_copy);
    208         NV_LUA_LOAD(lua_checkstack);
    209         NV_LUA_LOAD(lua_xmove);
    210 
    211 /* Access functions (stack -> C) */
    212         NV_LUA_LOAD(lua_isnumber);
    213         NV_LUA_LOAD(lua_isstring);
    214         NV_LUA_LOAD(lua_iscfunction);
    215         NV_LUA_LOAD(lua_isuserdata);
    216         NV_LUA_LOAD(lua_type);
    217         NV_LUA_LOAD(lua_typename);
    218 
    219         NV_LUA_LOAD(lua_tonumberx);
    220         NV_LUA_LOAD(lua_tointegerx);
    221         NV_LUA_LOAD(lua_tounsignedx);
    222         NV_LUA_LOAD(lua_toboolean);
    223         NV_LUA_LOAD(lua_tolstring);
    224         NV_LUA_LOAD(lua_rawlen);
    225         NV_LUA_LOAD(lua_tocfunction);
    226         NV_LUA_LOAD(lua_touserdata);
    227         NV_LUA_LOAD(lua_tothread);
    228         NV_LUA_LOAD(lua_topointer);
    229 
    230 /* Comparison and arithmetic functions */
    231         NV_LUA_LOAD(lua_arith);
    232         NV_LUA_LOAD(lua_rawequal);
    233         NV_LUA_LOAD(lua_compare);
    234 
    235 /* Push functions (C -> stack) */
    236         NV_LUA_LOAD(lua_pushnil);
    237         NV_LUA_LOAD(lua_pushnumber);
    238         NV_LUA_LOAD(lua_pushinteger);
    239         NV_LUA_LOAD(lua_pushunsigned);
    240         NV_LUA_LOAD(lua_pushlstring);
    241         NV_LUA_LOAD(lua_pushstring);
    242         NV_LUA_LOAD(lua_pushvfstring);
    243         NV_LUA_LOAD(lua_pushfstring);
    244         NV_LUA_LOAD(lua_pushcclosure);
    245         NV_LUA_LOAD(lua_pushboolean);
    246         NV_LUA_LOAD(lua_pushlightuserdata);
    247         NV_LUA_LOAD(lua_pushthread);
    248 
    249 /* Get functions (Lua -> stack) */
    250         NV_LUA_LOAD(lua_getglobal);
    251         NV_LUA_LOAD(lua_gettable);
    252         NV_LUA_LOAD(lua_getfield);
    253         NV_LUA_LOAD(lua_rawget);
    254         NV_LUA_LOAD(lua_rawgeti);
    255         NV_LUA_LOAD(lua_rawgetp);
    256         NV_LUA_LOAD(lua_createtable);
    257         NV_LUA_LOAD(lua_newuserdata);
    258         NV_LUA_LOAD(lua_getmetatable);
    259         NV_LUA_LOAD(lua_getuservalue);
    260 
    261 /* Set functions (stack -> Lua) */
    262         NV_LUA_LOAD(lua_setglobal);
    263         NV_LUA_LOAD(lua_settable);
    264         NV_LUA_LOAD(lua_setfield);
    265         NV_LUA_LOAD(lua_rawset);
    266         NV_LUA_LOAD(lua_rawseti);
    267         NV_LUA_LOAD(lua_rawsetp);
    268         NV_LUA_LOAD(lua_setmetatable);
    269         NV_LUA_LOAD(lua_setuservalue);
    270 
    271 /* 'load' and 'call' functions (load and run Lua code) */
    272         NV_LUA_LOAD(lua_callk);
    273         NV_LUA_LOAD(lua_getctx);
    274         NV_LUA_LOAD(lua_pcallk);
    275         NV_LUA_LOAD(lua_load);
    276         NV_LUA_LOAD(lua_dump);
    277 
    278 /* Coroutine functions */
    279         NV_LUA_LOAD(lua_yieldk);
    280         NV_LUA_LOAD(lua_resume);
    281         NV_LUA_LOAD(lua_status);
    282 
    283 /* Garbage-collection function and options */
    284         NV_LUA_LOAD(lua_gc);
    285 
    286 /* Miscellaneous functions */
    287         NV_LUA_LOAD(lua_error);
    288         NV_LUA_LOAD(lua_next);
    289         NV_LUA_LOAD(lua_concat);
    290         NV_LUA_LOAD(lua_len);
    291         NV_LUA_LOAD(lua_getallocf);
    292         NV_LUA_LOAD(lua_setallocf);
    293 
    294 /* Debug API */
    295         NV_LUA_LOAD(lua_getstack);
    296         NV_LUA_LOAD(lua_getinfo);
    297         NV_LUA_LOAD(lua_getlocal);
    298         NV_LUA_LOAD(lua_setlocal);
    299         NV_LUA_LOAD(lua_getupvalue);
    300         NV_LUA_LOAD(lua_setupvalue);
    301         NV_LUA_LOAD(lua_upvalueid);
    302         NV_LUA_LOAD(lua_upvaluejoin);
    303         NV_LUA_LOAD(lua_sethook);
    304         NV_LUA_LOAD(lua_gethook);
    305         NV_LUA_LOAD(lua_gethookmask);
    306         NV_LUA_LOAD(lua_gethookcount);
    307 
    308 /* lualib API */
    309         NV_LUA_LOAD(luaopen_base);
    310         NV_LUA_LOAD(luaopen_coroutine);
    311         NV_LUA_LOAD(luaopen_table);
    312         NV_LUA_LOAD(luaopen_io);
    313         NV_LUA_LOAD(luaopen_os);
    314         NV_LUA_LOAD(luaopen_string);
    315         NV_LUA_LOAD(luaopen_bit32);
    316         NV_LUA_LOAD(luaopen_math);
    317         NV_LUA_LOAD(luaopen_debug);
    318         NV_LUA_LOAD(luaopen_package);
    319         NV_LUA_LOAD(luaL_openlibs);
    320 
    321 /* lauxlib API */
    322         NV_LUA_LOAD(luaL_checkversion_);
    323         NV_LUA_LOAD(luaL_getmetafield);
    324         NV_LUA_LOAD(luaL_callmeta);
    325         NV_LUA_LOAD(luaL_tolstring);
    326         NV_LUA_LOAD(luaL_argerror);
    327         NV_LUA_LOAD(luaL_checklstring);
    328         NV_LUA_LOAD(luaL_optlstring);
    329         NV_LUA_LOAD(luaL_checknumber);
    330         NV_LUA_LOAD(luaL_optnumber);
    331         NV_LUA_LOAD(luaL_checkinteger);
    332         NV_LUA_LOAD(luaL_optinteger);
    333         NV_LUA_LOAD(luaL_checkunsigned);
    334         NV_LUA_LOAD(luaL_optunsigned);
    335         NV_LUA_LOAD(luaL_checkstack);
    336         NV_LUA_LOAD(luaL_checktype);
    337         NV_LUA_LOAD(luaL_checkany);
    338         NV_LUA_LOAD(luaL_newmetatable);
    339         NV_LUA_LOAD(luaL_setmetatable);
    340         NV_LUA_LOAD(luaL_testudata);
    341         NV_LUA_LOAD(luaL_checkudata);
    342         NV_LUA_LOAD(luaL_where);
    343         NV_LUA_LOAD(luaL_error);
    344         NV_LUA_LOAD(luaL_checkoption);
    345         NV_LUA_LOAD(luaL_fileresult);
    346         NV_LUA_LOAD(luaL_execresult);
    347 
    348         NV_LUA_LOAD(luaL_ref);
    349         NV_LUA_LOAD(luaL_unref);
    350         NV_LUA_LOAD(luaL_loadfilex);
    351         NV_LUA_LOAD(luaL_loadbufferx);
    352         NV_LUA_LOAD(luaL_loadstring);
    353         NV_LUA_LOAD(luaL_newstate);
    354         NV_LUA_LOAD(luaL_len);
    355         NV_LUA_LOAD(luaL_gsub);
    356         NV_LUA_LOAD(luaL_setfuncs);
    357         NV_LUA_LOAD(luaL_getsubtable);
    358         NV_LUA_LOAD(luaL_traceback);
    359         NV_LUA_LOAD(luaL_requiref);
    360 
    361 #       undef NV_LUA_LOAD
     57#undef NV_LUA_FUN
     58#undef NV_LUA_FUN_51
     59#undef NV_LUA_FUN_52
    36260        return true;
    36361}
Note: See TracChangeset for help on using the changeset viewer.