Skip to content

Commit

Permalink
Merge pull request #270 from nbd168/argv0
Browse files Browse the repository at this point in the history
main: add global ARGV0 variable
  • Loading branch information
jow- authored Jan 24, 2025
2 parents 175bfbd + af881af commit eb529ff
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ main(int argc, char **argv)
FILE *precompile = NULL;
char *outfile = NULL;
uc_vm_t vm = { 0 };
const char *argv0;
int opt, rv = 0;
const char *app;
uc_value_t *o;
Expand Down Expand Up @@ -558,6 +559,7 @@ main(int argc, char **argv)

uc_search_path_init(&config.module_search_path);

argv0 = argv[optind];
optind = 1;

uc_vm_init(&vm, &config);
Expand All @@ -569,6 +571,8 @@ main(int argc, char **argv)
o = ucv_array_new(&vm);

ucv_object_add(uc_vm_scope_get(&vm), "ARGV", ucv_get(o));
if (argv0)
ucv_object_add(uc_vm_scope_get(&vm), "SCRIPT_NAME", ucv_string_new(argv0));

/* parse options iteration 2: process remaining options */
while ((opt = getopt(argc, argv, optspec)) != -1)
Expand Down

0 comments on commit eb529ff

Please sign in to comment.