19static nlua_env cond_env = LUA_NOREF;
26 if (cond_env != LUA_NOREF)
29 cond_env = nlua_newEnv();
31 WARN(_(
"Failed to load standard Lua libraries."));
43 nlua_freeEnv(cond_env);
56 char buf[STRMAX_SHORT];
59 if (strstr( cond,
"return" ) != NULL) {
60 lua_pushstring(naevL, cond);
64 lua_pushstring(naevL,
"return ");
65 lua_pushstring(naevL, cond);
68 ret = luaL_loadbuffer( naevL, lua_tostring(naevL,-1), lua_strlen(naevL,-1),
"Lua Conditional" );
71 snprintf( buf,
sizeof(buf), _(
"Lua conditional syntax error: %s"), lua_tostring(naevL, -1));
74 snprintf( buf,
sizeof(buf), _(
"Lua Conditional ran out of memory: %s"), lua_tostring(naevL, -1));
79 ref = luaL_ref( naevL, LUA_REGISTRYINDEX );
101 char buf[STRMAX_SHORT];
104 if (strstr( cond,
"return" ) != NULL) {
105 lua_pushstring(naevL, cond);
109 lua_pushstring(naevL,
"return ");
110 lua_pushstring(naevL, cond);
111 lua_concat(naevL, 2);
113 ret = nlua_dobufenv(cond_env, lua_tostring(naevL,-1),
114 lua_strlen(naevL,-1),
"Lua Conditional");
117 snprintf( buf,
sizeof(buf), _(
"Lua conditional syntax error: %s"), lua_tostring(naevL, -1));
120 snprintf( buf,
sizeof(buf), _(
"Lua Conditional had a runtime error: %s"), lua_tostring(naevL, -1));
123 snprintf( buf,
sizeof(buf), _(
"Lua Conditional ran out of memory: %s"), lua_tostring(naevL, -1));
126 snprintf( buf,
sizeof(buf), _(
"Lua Conditional had an error while handling error function: %s"), lua_tostring(naevL, -1));
133 if (lua_isboolean(naevL, -1)) {
134 ret = !!lua_toboolean(naevL, -1);
138 lua_settop(naevL, 0);
142 snprintf( buf,
sizeof(buf), _(
"Lua Conditional didn't return a boolean"));
149 lua_settop(naevL, 0);
153int cond_checkChunk(
int chunk,
const char *cond )
155 char buf[STRMAX_SHORT];
158 if (chunk==LUA_NOREF) {
159 WARN(_(
"Trying to run Lua Conditional chunk that is not referenced!"));
163 ret = nlua_dochunkenv( cond_env, chunk,
"Lua Conditional" );
166 snprintf( buf,
sizeof(buf), _(
"Lua Conditional had a runtime error: %s"), lua_tostring(naevL, -1));
169 snprintf( buf,
sizeof(buf), _(
"Lua Conditional ran out of memory: %s"), lua_tostring(naevL, -1));
172 snprintf( buf,
sizeof(buf), _(
"Lua Conditional had an error while handling error function: %s"), lua_tostring(naevL, -1));
179 if (lua_isboolean(naevL, -1)) {
180 ret = !!lua_toboolean(naevL, -1);
184 lua_settop(naevL, 0);
188 snprintf( buf,
sizeof(buf), _(
"Lua Conditional didn't return a boolean"));
195 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.