#pragma once

#include "pxl8_cart.h"
#include "pxl8_gfx.h"
#include "pxl8_sfx.h"
#include "pxl8_types.h"

typedef struct pxl8_script pxl8_script;

#ifdef __cplusplus
extern "C" {
#endif

pxl8_script* pxl8_script_create(bool repl_mode);
void pxl8_script_destroy(pxl8_script* script);

const char* pxl8_script_get_last_error(pxl8_script* script);
bool pxl8_script_is_incomplete_input(pxl8_script* script);

void pxl8_script_set_cart_path(pxl8_script* script, const char* cart_path, const char* original_cwd);
void pxl8_script_set_gfx(pxl8_script* script, pxl8_gfx* gfx);
void pxl8_script_set_input(pxl8_script* script, pxl8_input_state* input);
void pxl8_script_set_rng(pxl8_script* script, void* rng);
void pxl8_script_set_sfx(pxl8_script* script, pxl8_sfx_mixer* mixer);
void pxl8_script_set_sys(pxl8_script* script, void* sys);

pxl8_result pxl8_script_call_function(pxl8_script* script, const char* name);
pxl8_result pxl8_script_call_function_f32(pxl8_script* script, const char* name, f32 arg);
bool pxl8_script_check_reload(pxl8_script* script);
pxl8_result pxl8_script_eval(pxl8_script* script, const char* code);
pxl8_result pxl8_script_eval_repl(pxl8_script* script, const char* code);
pxl8_result pxl8_script_load_cart_manifest(pxl8_script* script, pxl8_cart* cart);
pxl8_result pxl8_script_load_main(pxl8_script* script, const char* path);
pxl8_result pxl8_script_load_module(pxl8_script* script, const char* module_name);
pxl8_result pxl8_script_run_fennel_file(pxl8_script* script, const char* filename);
pxl8_result pxl8_script_run_file(pxl8_script* script, const char* filename);

u32 pxl8_script_serialize_globals(pxl8_script* script, u8** out_data);
void pxl8_script_deserialize_globals(pxl8_script* script, const u8* data, u32 size);
void pxl8_script_free_serialized(u8* data);

#ifdef __cplusplus
}
#endif
