Skip to content

Commit

Permalink
std
Browse files Browse the repository at this point in the history
  • Loading branch information
nic-gaffney committed Jun 28, 2023
1 parent 73843fa commit 8262abd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
9 changes: 9 additions & 0 deletions examples/arguments.sloth
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn main(argc: Int, argv: [String]) Int {
if argc == 2 {
print("The argument supplied is ");
println(argv);
} else {
println("Wrong # of args");
}
return 0;
}
3 changes: 2 additions & 1 deletion examples/guessing.sloth
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ fn main() Int {
}

print("It took you ");
print(istr(tries));
var s: String = istr(tries);
print(s);
println(" to guess correctly!");

return 0;
Expand Down
5 changes: 5 additions & 0 deletions examples/system.sloth
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() Int {
system("neofetch");
println(istr(12));
return 0;
}
2 changes: 1 addition & 1 deletion std/stdlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int as_int(float x) {
}

char* istr(int x) {
char* snum[100];
char* snum = malloc(12);
sprintf(snum, "%d", x);
//char* result = snum;
return snum;
Expand Down
1 change: 1 addition & 0 deletions std/stdlib.sloth
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ foreign fn parse_int(str: String) Int;
foreign fn termpos(x: Int, y: Int);
foreign fn as_int(x: Float) Int;
foreign fn istr(x: Int) String;
foreign fn system(cmd: String) Int;

foreign fn termclear() Void;

0 comments on commit 8262abd

Please sign in to comment.