naev 0.10.4
nluadef.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
7#include <lauxlib.h>
8#include <lua.h>
9#include <lualib.h>
12#include "attributes.h"
13#include "log.h"
14
15/*
16 * A number of lua error functions don't ruturn, but arnen't marked
17 * as such. These redeclarations ensure that the compiler and analizer are
18 * aware that no return will take place when compiling our code.
19 */
20#pragma GCC diagnostic push
21#pragma GCC diagnostic ignored "-Wredundant-decls"
22
23NORETURN extern int lua_error( lua_State *L );
24NORETURN extern int luaL_error( lua_State *L, const char *fmt, ... );
25NORETURN extern int luaL_typerror( lua_State *L, int narg, const char *tname );
26
27#pragma GCC diagnostic pop
28
29/*
30 * debug stuff
31 */
32#ifdef DEBUG_PARANOID
33#define NLUA_DEBUG(str, args...) \
34 (DEBUG("Lua: "str"\n", ## args), abort())
35#else /* DEBUG_PARANOID */
36#define NLUA_DEBUG(str, args...) \
37 (DEBUG("Lua: "str"\n", ## args))
38#endif /* DEBUG_PARANOID */
39#define NLUA_INVALID_PARAMETER(L) \
40{ \
41 DEBUG( "Invalid parameter for %s.", __func__ ); \
42 luaL_error( L, "Invalid parameter for %s.", __func__ ); \
43 return 0; \
44}
45#define NLUA_MIN_ARGS(n) \
46 if (lua_gettop(L) < n) { \
47 DEBUG( "Too few arguments for %s.", __func__ ); \
48 luaL_error( L, "Too few arguments for %s.", __func__ ); \
49 return 0; \
50 }
51
52/*
53 * Error stuff.
54 */
55#define NLUA_ERROR(L,str, args...) (luaL_error(L,str, ## args))