18static nlua_env cond_env = LUA_NOREF;
25 if ( cond_env != LUA_NOREF )
28 cond_env = nlua_newEnv(
"cond" );
30 WARN( _(
"Failed to load standard Lua libraries." ) );
42 nlua_freeEnv( cond_env );
55 char buf[STRMAX_SHORT];
58 if ( strstr( cond,
"return" ) != NULL ) {
59 lua_pushstring(
naevL, cond );
62 lua_pushstring(
naevL,
"return " );
63 lua_pushstring(
naevL, cond );
64 lua_concat(
naevL, 2 );
66 ret = luaL_loadbuffer(
naevL, lua_tostring(
naevL, -1 ),
67 lua_strlen(
naevL, -1 ),
"Lua Conditional" );
70 snprintf( buf,
sizeof( buf ), _(
"Lua conditional syntax error: %s" ),
71 lua_tostring(
naevL, -1 ) );
74 snprintf( buf,
sizeof( buf ),
75 _(
"Lua Conditional ran out of memory: %s" ),
76 lua_tostring(
naevL, -1 ) );
81 ref = luaL_ref(
naevL, LUA_REGISTRYINDEX );
90 lua_settop(
naevL, 0 );
103 char buf[STRMAX_SHORT];
106 if ( strstr( cond,
"return" ) != NULL ) {
107 lua_pushstring(
naevL, cond );
110 lua_pushstring(
naevL,
"return " );
111 lua_pushstring(
naevL, cond );
112 lua_concat(
naevL, 2 );
114 ret = nlua_dobufenv( cond_env, lua_tostring(
naevL, -1 ),
115 lua_strlen(
naevL, -1 ),
"Lua Conditional" );
118 snprintf( buf,
sizeof( buf ), _(
"Lua conditional syntax error: %s" ),
119 lua_tostring(
naevL, -1 ) );
122 snprintf( buf,
sizeof( buf ),
123 _(
"Lua Conditional had a runtime error: %s" ),
124 lua_tostring(
naevL, -1 ) );
127 snprintf( buf,
sizeof( buf ),
128 _(
"Lua Conditional ran out of memory: %s" ),
129 lua_tostring(
naevL, -1 ) );
134 _(
"Lua Conditional had an error while handling error function: %s" ),
135 lua_tostring(
naevL, -1 ) );
142 if ( lua_isboolean(
naevL, -1 ) ) {
143 ret = !!lua_toboolean(
naevL, -1 );
147 lua_settop(
naevL, 0 );
151 snprintf( buf,
sizeof( buf ),
152 _(
"Lua Conditional didn't return a boolean" ) );
159 lua_settop(
naevL, 0 );
163int cond_checkChunk(
int chunk,
const char *cond )
165 char buf[STRMAX_SHORT];
168 if ( chunk == LUA_NOREF ) {
170 _(
"Trying to run Lua Conditional chunk that is not referenced!" ) );
174 ret = nlua_dochunkenv( cond_env, chunk,
"Lua Conditional" );
177 snprintf( buf,
sizeof( buf ),
178 _(
"Lua Conditional had a runtime error: %s" ),
179 lua_tostring(
naevL, -1 ) );
182 snprintf( buf,
sizeof( buf ),
183 _(
"Lua Conditional ran out of memory: %s" ),
184 lua_tostring(
naevL, -1 ) );
189 _(
"Lua Conditional had an error while handling error function: %s" ),
190 lua_tostring(
naevL, -1 ) );
197 if ( lua_isboolean(
naevL, -1 ) ) {
198 ret = !!lua_toboolean(
naevL, -1 );
202 lua_settop(
naevL, 0 );
206 snprintf( buf,
sizeof( buf ),
207 _(
"Lua Conditional didn't return a boolean" ) );
214 lua_settop(
naevL, 0 );
int cond_check(const char *cond)
Checks to see if a condition is true.
void cond_exit(void)
Destroys the conditional subsystem.
int cond_init(void)
Initializes the conditional subsystem.
int cond_compile(const char *cond)
Compiles a conditional statement that can then be used as a reference.
Header file with generic functions and naev-specifics.
int nlua_loadStandard(nlua_env env)
Loads the standard Naev Lua API.
void print_with_line_numbers(const char *str)
Prints to stderr with line numbers.