1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-12-18 21:41:53 +03:00
mobile-nixos/overlay/mruby-builder/mruby/stub.c
2020-02-28 23:14:09 -05:00

55 lines
1.1 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <stdlib.h>
#include <string.h>
#include <mruby.h>
#include <mruby/array.h>
#include <mruby/irep.h>
#include <mruby/variable.h>
// Assumes this is produced by builder.nix
#include "irep.c"
int
main(int argc, char **argv)
{
int i;
mrb_value ARGV;
mrb_sym dollar_zero;
mrb_sym program_name;
mrb_state *mrb = mrb_open();
if (!mrb) {
/* handle error */
printf("[FATAL] Could not open mruby.\n");
exit(1);
}
ARGV = mrb_ary_new_capa(mrb, argc);
// Skip the program name here.
for (i = 1; i < argc; i++) {
mrb_ary_push(mrb, ARGV, mrb_str_new(mrb, argv[i], strlen(argv[i])));
}
mrb_define_global_const(mrb, "ARGV", ARGV);
// $0
dollar_zero = mrb_intern_lit(mrb, "$0");
mrb_gv_set(mrb, dollar_zero, mrb_str_new(mrb, argv[0], strlen(argv[0])));
// $PROGRAM_NAME
program_name = mrb_intern_lit(mrb, "$PROGRAM_NAME");
mrb_gv_set(mrb, program_name, mrb_str_new(mrb, argv[0], strlen(argv[0])));
mrb_load_irep(mrb, ruby_irep);
if (mrb->exc) {
mrb_print_backtrace(mrb);
mrb_print_error(mrb);
mrb_close(mrb);
exit(1);
}
mrb_close(mrb);
return 0;
}