naev 0.12.5
nlua.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
7#include <lauxlib.h> // IWYU pragma: export
8#include <lua.h> // IWYU pragma: export
9
10#include "log.h" // IWYU pragma: export
12
13#define NLUA_LOAD_TABLE \
14 "_LOADED"
15
16#define NLUA_DONE "__done__"
17#define NLUA_DEPRECATED( L, f ) \
18 do { \
19 lua_pushfstring( L, _( "Deprecated function call: %s" ), f ); \
20 nlua_warn( L, -1 ); \
21 } while ( 0 )
22#define NLUA_WARN( L, str, ... ) \
23 do { \
24 lua_pushfstring( L, str, ##__VA_ARGS__ ); \
25 nlua_warn( L, -1 ); \
26 } while ( 0 )
27
28#define nluaL_optarg( L, ind, def, checkfunc ) \
29 ( lua_isnoneornil( L, ind ) ? ( def ) : checkfunc( L, ind ) )
30
31typedef int nlua_env;
32extern lua_State *naevL;
33extern nlua_env __NLUA_CURENV;
34
35/*
36 * standard Lua stuff wrappers
37 */
38void lua_init( void );
39void lua_exit( void );
40int nlua_warn( lua_State *L, int idx );
41void lua_clearCache( void );
42nlua_env nlua_newEnv( const char *name );
43void nlua_freeEnv( nlua_env env );
44void nlua_pushenv( lua_State *L, nlua_env env );
45void nlua_setenv( lua_State *L, nlua_env env, const char *name );
46void nlua_getenv( lua_State *L, nlua_env env, const char *name );
47void nlua_register( nlua_env env, const char *libname, const luaL_Reg *l,
48 int metatable );
49int nlua_dobufenv( nlua_env env, const char *buff, size_t sz,
50 const char *name );
51int nlua_dofileenv( nlua_env env, const char *filename );
52int nlua_dochunkenv( nlua_env env, int chunk, const char *name );
53int nlua_loadStandard( nlua_env env );
54int nlua_errTrace( lua_State *L );
55int nlua_pcall( nlua_env env, int nargs, int nresults );
56int nlua_refenv( nlua_env env, const char *name );
57int nlua_refenvtype( nlua_env env, const char *name, int type );
58int nlua_reffield( int objref, const char *name );
59
60/* Reference stuff. */
61int nlua_ref( lua_State *L, int idx );
62void nlua_unref( lua_State *L, int idx );
63
64/* Hack to handle resizes. */
65void nlua_resize( void );
66
67/* Useful stuff that we want to reuse. */
68int nlua_helperTags( lua_State *L, int idx, char *const *tags );
69
70#if DEBUGGING
71void nlua_pushEnvTable( lua_State *L );
72#endif /* DEBUGGING */
void nlua_unref(lua_State *L, int idx)
Removes a reference set with nlua_ref.
Definition nlua.c:1088
int nlua_refenv(nlua_env env, const char *name)
Gets the reference of a global in a lua environment.
Definition nlua.c:1029
int nlua_ref(lua_State *L, int idx)
Creates a new reference to a Lua structure at a position.
Definition nlua.c:1079
int nlua_loadStandard(nlua_env env)
Loads the standard Naev Lua API.
Definition nlua.c:914
nlua_env __NLUA_CURENV
Definition nlua.c:55
int nlua_refenvtype(nlua_env env, const char *name, int type)
Gets the reference of a global in a lua environment if it matches a type.
Definition nlua.c:1047
int nlua_helperTags(lua_State *L, int idx, char *const *tags)
Helper function to deal with tags.
Definition nlua.c:1118
int nlua_reffield(int objref, const char *name)
Gets the reference to the specified field from an object reference.
Definition nlua.c:1063
void lua_clearCache(void)
Clears the cached stuff.
Definition nlua.c:269
void nlua_resize(void)
Propagates a resize event to all the environments forcibly.
Definition nlua.c:1097
lua_State * naevL
Definition nlua.c:54
int nlua_errTrace(lua_State *L)
Gets a trace from Lua.
Definition nlua.c:946