2021-11-30 21:29:18 -06:00
|
|
|
#include "script.h"
|
|
|
|
|
2022-08-01 13:32:58 -05:00
|
|
|
#include "stdio.h"
|
2022-08-03 17:00:00 -05:00
|
|
|
#include "log.h"
|
2022-06-21 12:48:19 -05:00
|
|
|
|
2022-08-01 13:32:58 -05:00
|
|
|
#include "mruby.h"
|
|
|
|
#include "mruby/compile.h"
|
2022-08-03 17:00:00 -05:00
|
|
|
#include "mrbffi.h"
|
2022-06-21 12:48:19 -05:00
|
|
|
|
2022-08-03 17:00:00 -05:00
|
|
|
mrb_value obj;
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-08-03 17:00:00 -05:00
|
|
|
mrb_state *mrb;
|
|
|
|
mrbc_context *c;
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-08-01 13:32:58 -05:00
|
|
|
void script_init() {
|
|
|
|
mrb = mrb_open();
|
2022-08-03 17:00:00 -05:00
|
|
|
c = mrbc_context_new(mrb);
|
|
|
|
ffi_load();
|
2021-11-30 21:29:18 -06:00
|
|
|
}
|
|
|
|
|
2022-08-01 13:32:58 -05:00
|
|
|
void script_run(const char *script) {
|
|
|
|
mrb_load_string(mrb, script);
|
2022-02-06 10:14:57 -06:00
|
|
|
}
|
2022-08-01 13:32:58 -05:00
|
|
|
|
|
|
|
void script_dofile(const char *file) {
|
|
|
|
FILE *mrbf = fopen(file, "r");
|
2022-08-03 17:00:00 -05:00
|
|
|
if (mrbf == NULL) {
|
|
|
|
YughError("Could not find game.rb in root folder.",0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mrbc_filename(mrb, c, file);
|
|
|
|
obj = mrb_load_file_cxt(mrb, mrbf, c);
|
|
|
|
mrb_print_error(mrb);
|
2022-08-01 13:32:58 -05:00
|
|
|
fclose(mrbf);
|
2022-08-03 17:00:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void script_update() {
|
|
|
|
mrb_funcall(mrb, obj, "update", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void script_draw() {
|
|
|
|
mrb_funcall(mrb, obj, "draw", 0);
|
2022-08-01 13:32:58 -05:00
|
|
|
}
|