1 /* 2 * See Licensing and Copyright notice in naev.h 3 */ 4 5 6 #ifndef NLUADEF_H 7 # define NLUADEF_H 8 9 10 #include <lua.h> 11 #include <lauxlib.h> 12 #include <lualib.h> 13 #include "log.h" 14 15 16 /* 17 * debug stuff 18 */ 19 #ifdef DEBUGGING 20 #ifdef DEBUG_PARANOID 21 #define NLUA_DEBUG(str, args...) \ 22 (DEBUG("Lua: "str"\n", ## args), abort()) 23 #else /* DEBUG_PARANOID */ 24 #define NLUA_DEBUG(str, args...) \ 25 (DEBUG("Lua: "str"\n", ## args)) 26 #endif /* DEBUG_PARANOID */ 27 #define NLUA_INVALID_PARAMETER(L) \ 28 { \ 29 DEBUG( "Invalid parameter for %s.", __func__ ); \ 30 luaL_error( L, "Invalid parameter for %s.", __func__ ); \ 31 return 0; \ 32 } 33 #define NLUA_MIN_ARGS(n) \ 34 if (lua_gettop(L) < n) { \ 35 DEBUG( "Too few arguments for %s.", __func__ ); \ 36 luaL_error( L, "Too few arguments for %s.", __func__ ); \ 37 return 0; \ 38 } 39 40 41 #else /* DEBUGGING */ 42 #define NLUA_DEBUG(str, args...) do {;} while(0) 43 #define NLUA_MIN_ARGS(n) do {;} while(0) 44 #define NLUA_INVALID_PARAMETER(L) do {;} while(0) 45 #endif /* DEBUGGING */ 46 47 48 /* 49 * Error stuff. 50 */ 51 #define NLUA_ERROR(L,str, args...) (luaL_error(L,str, ## args)) 52 53 #define NLUA_CHECKRW(L) \ 54 { \ 55 nlua_getenv(__NLUA_CURENV, "__RW"); \ 56 if (!lua_toboolean(L, -1)) { \ 57 DEBUG( "Cannot call %s in read-only environment.", __func__ ); \ 58 luaL_error( L, "Cannot call %s in read-only environment.", __func__ ); \ 59 return 0; \ 60 } \ 61 lua_pop(L, 1); \ 62 } 63 64 65 #endif /* NLUADEF_H */ 66