Assign __main__ as name of executed scripts

This commit is contained in:
K. Lange 2021-01-07 10:58:04 +09:00
parent 4266bf60e7
commit 8a1de6c4d2
4 changed files with 7 additions and 1 deletions

View File

@ -204,7 +204,7 @@ int main(int argc, char * argv[]) {
* collect the result of the last one and use it as the
* exit code if it's an integer. */
for (int i = optind; i < argc; ++i) {
KrkValue out = krk_runfile(argv[i],1,"<module>",argv[i]);
KrkValue out = krk_runfile(argv[i],1,"__main__",argv[i]);
if (i + 1 == argc) result = out;
}
}

View File

@ -0,0 +1 @@
Hello, world: dummy I am a module.

4
test/testModuleName.krk Normal file
View File

@ -0,0 +1,4 @@
if __name__ == '__main__':
print("You called me directly!")
else:
print("My name is",__name__,"so I must have been imported.")

View File

@ -0,0 +1 @@
You called me directly!