Add kuroko.argv
This commit is contained in:
parent
2f7503cd0d
commit
2bd0d93596
9
kuroko.c
9
kuroko.c
@ -305,6 +305,15 @@ int main(int argc, char * argv[]) {
|
||||
|
||||
krk_initVM(flags);
|
||||
|
||||
/* Attach kuroko.argv - argv[0] will be set to an empty string for the repl */
|
||||
if (argc == optind) krk_push(OBJECT_VAL(krk_copyString("",0)));
|
||||
for (int arg = optind; arg < argc; ++arg) {
|
||||
krk_push(OBJECT_VAL(krk_copyString(argv[arg],strlen(argv[arg]))));
|
||||
}
|
||||
KrkValue argList = krk_list_of(argc - optind + (optind == argc), &vm.stackTop[-(argc - optind + (optind == argc))]);
|
||||
krk_attachNamedValue(&vm.system->fields, "argv", argList);
|
||||
for (int arg = optind; arg < argc + (optind == argc); ++arg) krk_pop();
|
||||
|
||||
/* Bind interrupt signal */
|
||||
signal(SIGINT, handleSigint);
|
||||
|
||||
|
4
test/testArgv.krk
Normal file
4
test/testArgv.krk
Normal file
@ -0,0 +1,4 @@
|
||||
import kuroko
|
||||
|
||||
print(kuroko.argv)
|
||||
# ['test/testArgv.krk']
|
1
test/testArgv.krk.expect
Normal file
1
test/testArgv.krk.expect
Normal file
@ -0,0 +1 @@
|
||||
['test/testArgv.krk']
|
2
vm.c
2
vm.c
@ -509,7 +509,7 @@ KrkValue krk_runNext(void) {
|
||||
* Exposed method called to produce lists from [expr,...] sequences in managed code.
|
||||
* Presented in the global namespace as listOf(...)
|
||||
*/
|
||||
static KrkValue krk_list_of(int argc, KrkValue argv[]) {
|
||||
KrkValue krk_list_of(int argc, KrkValue argv[]) {
|
||||
KrkValue Class;
|
||||
krk_tableGet(&vm.builtins->fields,OBJECT_VAL(S("list")), &Class);
|
||||
KrkInstance * outList = krk_newInstance(AS_CLASS(Class));
|
||||
|
1
vm.h
1
vm.h
@ -139,6 +139,7 @@ extern KrkValue krk_typeOf(int argc, KrkValue argv[]);
|
||||
extern int krk_bindMethod(KrkClass * _class, KrkString * name);
|
||||
extern int krk_callValue(KrkValue callee, int argCount, int extra);
|
||||
|
||||
extern KrkValue krk_list_of(int argc, KrkValue argv[]);
|
||||
extern KrkValue krk_dict_of(int argc, KrkValue argv[]);
|
||||
extern KrkValue krk_callSimple(KrkValue value, int argCount, int isMethod);
|
||||
extern void krk_finalizeClass(KrkClass * _class);
|
||||
|
Loading…
Reference in New Issue
Block a user