Skip to content

Commit

Permalink
feat: Add std::scan for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
quantumsheep committed Jul 17, 2020
1 parent 448cbc9 commit a80f121
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions std/io.sn
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace std {
#[target_os = "windows"]
namespace std {
extern fn WriteConsoleA(i8*, i8*, u64, u64*, void*) : bool;
extern fn ReadConsoleA(i8*, i8*, u64, u64*, void*) : bool;
extern fn GetStdHandle(u64): i8*;

fn print(str: i8*) {
Expand All @@ -27,6 +28,20 @@ namespace std {

std::memory::deallocate(count);
}

fn scan() : std::string {
let handle = GetStdHandle(-10);
let ptr = std::memory::allocate<i8>(4096);

let read: u64 = 0;
ReadConsoleA(handle, ptr, 4096, &read, null);

let str = string::new(ptr, read - 1);

std::memory::deallocate(ptr);

return str;
}
}

namespace std {
Expand Down

0 comments on commit a80f121

Please sign in to comment.