naev 0.12.6
nluadef.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
7#include <assert.h>
8#include <lauxlib.h>
9#include <lua.h>
10#include <lualib.h>
12
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, ... ) ( DEBUG( "Lua: " str "\n", ##__VA_ARGS__ ) )
41#endif /* DEBUG_PARANOID */
42#define NLUA_INVALID_PARAMETER( L, idx ) \
43 { \
44 DEBUG( "Invalid parameter %d for %s.", idx, __func__ ); \
45 return luaL_error( L, "Invalid parameter %d for %s.", idx, __func__ ); \
46 }
47#define NLUA_INVALID_PARAMETER_NORET( L, idx ) \
48 { \
49 DEBUG( "Invalid parameter %d for %s.", idx, __func__ ); \
50 luaL_error( L, "Invalid parameter %d for %s.", idx, __func__ ); \
51 }
52#define NLUA_MIN_ARGS( n ) \
53 if ( lua_gettop( L ) < n ) { \
54 DEBUG( "Too few arguments for %s.", __func__ ); \
55 return luaL_error( L, "Too few arguments for %s.", __func__ ); \
56 }
57
58/*
59 * Error stuff.
60 */
61#define NLUA_ERROR( L, str, ... ) ( luaL_error( L, str, ##__VA_ARGS__ ) )