naev 0.11.5
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>
10#include <assert.h>
13#include "attributes.h"
14#include "log.h"
15
16/* Fixes clangd warning about #pragma GCC diagnostic pop
17 * See: https://github.com/clangd/clangd/issues/1167 */
18static_assert(1,"");
19/*
20 * A number of Lua error functions don't return, but aren't marked
21 * as such. These redeclarations ensure that the compiler and analyzer are
22 * aware that no return will take place when compiling our code.
23 */
24#pragma GCC diagnostic push
25#pragma GCC diagnostic ignored "-Wredundant-decls"
26
27NORETURN extern int lua_error( lua_State *L );
28NORETURN extern int luaL_error( lua_State *L, const char *fmt, ... );
29NORETURN extern int luaL_typerror( lua_State *L, int narg, const char *tname );
30
31#pragma GCC diagnostic pop
32
33/*
34 * debug stuff
35 */
36#ifdef DEBUG_PARANOID
37#define NLUA_DEBUG(str, ...) \
38 (DEBUG("Lua: "str"\n", ## __VA_ARGS__), abort())
39#else /* DEBUG_PARANOID */
40#define NLUA_DEBUG(str, ...) \
41 (DEBUG("Lua: "str"\n", ## __VA_ARGS__))
42#endif /* DEBUG_PARANOID */
43#define NLUA_INVALID_PARAMETER(L,idx) \
44{ \
45 DEBUG( "Invalid parameter %d for %s.", idx, __func__ ); \
46 return luaL_error( L, "Invalid parameter %d for %s.", idx, __func__ ); \
47}
48#define NLUA_INVALID_PARAMETER_NORET(L,idx) \
49{ \
50 DEBUG( "Invalid parameter %d for %s.", idx, __func__ ); \
51 luaL_error( L, "Invalid parameter %d for %s.", idx, __func__ ); \
52}
53#define NLUA_MIN_ARGS(n) \
54 if (lua_gettop(L) < n) { \
55 DEBUG( "Too few arguments for %s.", __func__ ); \
56 return luaL_error( L, "Too few arguments for %s.", __func__ ); \
57 }
58
59/*
60 * Error stuff.
61 */
62#define NLUA_ERROR(L,str, ...) (luaL_error(L,str, ## __VA_ARGS__))