92c5cd59f5
- Create stdlib/Std/Io.bux with extern func declarations
- Rename C shim functions to short names (PrintLine, PrintInt, etc.)
- Update all 9 examples to use import Std::Io::{PrintLine, PrintInt};
- Remove manual extern func Std_Io_* declarations from examples
50 lines
1002 B
C
50 lines
1002 B
C
/* Bux Standard Library - I/O functions */
|
|
|
|
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
|
|
/* PrintLine - print string with newline */
|
|
void PrintLine(const char* s) {
|
|
if (s != NULL) {
|
|
puts(s);
|
|
} else {
|
|
puts("");
|
|
}
|
|
}
|
|
|
|
/* Print - print string without newline */
|
|
void Print(const char* s) {
|
|
if (s != NULL) {
|
|
printf("%s", s);
|
|
}
|
|
}
|
|
|
|
/* PrintInt - print integer */
|
|
void PrintInt(int64_t n) {
|
|
printf("%lld", (long long)n);
|
|
}
|
|
|
|
/* PrintFloat - print float */
|
|
void PrintFloat(double f) {
|
|
printf("%g", f);
|
|
}
|
|
|
|
/* PrintBool - print boolean */
|
|
void PrintBool(int b) {
|
|
printf("%s", b ? "true" : "false");
|
|
}
|
|
|
|
/* ReadLine - read line from stdin (simplified) */
|
|
const char* ReadLine(void) {
|
|
static char buffer[1024];
|
|
if (fgets(buffer, sizeof(buffer), stdin) != NULL) {
|
|
size_t len = strlen(buffer);
|
|
if (len > 0 && buffer[len-1] == '\n') {
|
|
buffer[len-1] = '\0';
|
|
}
|
|
return buffer;
|
|
}
|
|
return "";
|
|
}
|