diff options
| author | Cody <cody@codyq.dev> | 2023-06-28 22:10:41 -0500 |
|---|---|---|
| committer | Cody <cody@codyq.dev> | 2023-06-28 22:10:41 -0500 |
| commit | c4d6a1229c35cc889a1db53cf1c9d87d2f662238 (patch) | |
| tree | d49d20c7057b520b9140559333cba8a918242116 | |
| parent | 1349ebd2fc2a08a45c8e138002c5254ee6978540 (diff) | |
| parent | 8262abdea18cdb873b2012411bfebe131fb37d52 (diff) | |
| download | sloth-c4d6a1229c35cc889a1db53cf1c9d87d2f662238.tar.gz | |
Merge branch 'master' of github.com:slothlang/slothlang
| -rw-r--r-- | examples/arguments.sloth | 9 | ||||
| -rw-r--r-- | examples/guessing.sloth | 3 | ||||
| -rw-r--r-- | examples/system.sloth | 5 | ||||
| -rw-r--r-- | std/stdlib.c | 2 | ||||
| -rw-r--r-- | std/stdlib.sloth | 1 |
5 files changed, 18 insertions, 2 deletions
diff --git a/examples/arguments.sloth b/examples/arguments.sloth new file mode 100644 index 0000000..3e44dcc --- /dev/null +++ b/examples/arguments.sloth @@ -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; +} diff --git a/examples/guessing.sloth b/examples/guessing.sloth index 49c0bde..ef680c9 100644 --- a/examples/guessing.sloth +++ b/examples/guessing.sloth @@ -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; diff --git a/examples/system.sloth b/examples/system.sloth new file mode 100644 index 0000000..affe588 --- /dev/null +++ b/examples/system.sloth @@ -0,0 +1,5 @@ +fn main() Int { + system("neofetch"); + println(istr(12)); + return 0; +} diff --git a/std/stdlib.c b/std/stdlib.c index 3878817..4a650a4 100644 --- a/std/stdlib.c +++ b/std/stdlib.c @@ -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; diff --git a/std/stdlib.sloth b/std/stdlib.sloth index 4213e0a..4d3617f 100644 --- a/std/stdlib.sloth +++ b/std/stdlib.sloth @@ -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; |
