#include "apfl.h" #include "context.h" void apfl_build_native_and_bytecode_combined_module( apfl_ctx ctx, apfl_stackidx native, struct apfl_string_view bytecode ) { apfl_move_to_top_of_stack(ctx, native); struct apfl_io_string_reader_data reader = apfl_io_string_reader_create(bytecode); struct apfl_io_reader r = apfl_io_string_reader(&reader); apfl_load_bytecode(ctx, r); apfl_list_create(ctx, 0); apfl_call(ctx, -2, -1); apfl_list_create(ctx, 1); apfl_list_append(ctx, -1, -3); apfl_call(ctx, -2, -1); } static int cmod_searcher_registry_key; bool apfl_modules_query(apfl_ctx ctx, apfl_stackidx modname) { apfl_move_to_top_of_stack(ctx, modname); if (!apfl_registry_try_get(ctx, &cmod_searcher_registry_key, 0)) { apfl_drop(ctx, -1); return false; } return apfl_get_member_if_exists(ctx, -1, -2); } void apfl_modules_register(apfl_ctx ctx, const char *name, apfl_stackidx modloader) { apfl_move_to_top_of_stack(ctx, modloader); if (!apfl_registry_try_get(ctx, &cmod_searcher_registry_key, 0)) { apfl_dict_create(ctx); } apfl_push_const_string(ctx, name); apfl_dict_set(ctx, -2, -1, -3); apfl_registry_set(ctx, &cmod_searcher_registry_key, 0, -1); }