-#include <assert.h>
+#include "system/stacktrace.h"
#include "ebisp/gc.h"
#include "ebisp/interpreter.h"
#include "ebisp/parser.h"
#include "ebisp/scope.h"
+#include "ebisp/std.h"
+#include "game/level.h"
+#include "game/level_script.h"
#include "script.h"
#include "str.h"
-#include "system/error.h"
#include "system/line_stream.h"
#include "system/log.h"
+#include "system/log_script.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
#include "ui/console.h"
+#include "game_script.h"
struct Script
{
struct Scope scope;
};
-static struct EvalResult
-hide_goal(void *param, Gc *gc, struct Scope *scope, struct Expr args)
+Script *create_script_from_line_stream(LineStream *line_stream, Game *game)
{
- assert(param);
- assert(gc);
- assert(scope);
- (void) args;
-
- /* TODO: hide_goal is not implemented */
-
- return eval_success(NIL(gc));
-}
-
-static struct EvalResult
-show_goal(void *param, Gc *gc, struct Scope *scope, struct Expr args)
-{
- assert(param);
- assert(gc);
- assert(scope);
- (void) args;
-
- /* TODO: show_goal is not implemented */
-
- return eval_success(NIL(gc));
-}
-
-Script *create_script_from_line_stream(LineStream *line_stream, Level *level)
-{
- assert(line_stream);
+ trace_assert(line_stream);
Lt *lt = create_lt();
if (lt == NULL) {
Script *script = PUSH_LT(lt, nth_alloc(sizeof(Script)), free);
if (script == NULL) {
- throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
}
script->lt = lt;
script->scope = create_scope(script->gc);
+ load_std_library(script->gc, &script->scope);
+ load_log_library(script->gc, &script->scope);
+ load_game_library(script->gc, &script->scope, game);
+
size_t n = 0;
sscanf(line_stream_next(line_stream), "%lu", &n);
}
PUSH_LT(lt, source_code, free);
- set_scope_value(
- script->gc,
- &script->scope,
- SYMBOL(script->gc, "rect-apply-force"),
- NATIVE(script->gc, rect_apply_force, level));
- set_scope_value(
- script->gc,
- &script->scope,
- SYMBOL(script->gc, "hide-goal"),
- NATIVE(script->gc, hide_goal, level));
- set_scope_value(
- script->gc,
- &script->scope,
- SYMBOL(script->gc, "show-goal"),
- NATIVE(script->gc, show_goal, level));
-
struct ParseResult parse_result =
read_all_exprs_from_string(
script->gc,
void destroy_script(Script *script)
{
- assert(script);
+ trace_assert(script);
RETURN_LT0(script->lt);
}
int script_eval(Script *script, const char *source_code)
{
- assert(script);
- assert(source_code);
+ trace_assert(script);
+ trace_assert(source_code);
struct ParseResult parse_result = read_expr_from_string(
script->gc,
parse_result.expr);
if (eval_result.is_error) {
log_fail("Evaluation error: ");
+ /* TODO(#521): Evalation error is prepended with `[FAIL]` at the end of the message */
/* TODO(#486): print_expr_as_sexpr could not be easily integrated with log_fail */
print_expr_as_sexpr(stderr, eval_result.expr);
log_fail("\n");