Cosmo/src/cbaselib.c

20 lines
568 B
C
Raw Normal View History

2020-10-28 05:16:30 +00:00
#include "cbaselib.h"
#include "cvalue.h"
#include "cobj.h"
#include "cmem.h"
2020-10-28 05:16:30 +00:00
void cosmoB_loadlibrary(CState *state) {
cosmoM_freezeGC(state);
2020-10-28 05:16:30 +00:00
cosmoV_register(state, "print", cosmoV_newObj(cosmoO_newCFunction(state, cosmoB_print)));
cosmoM_unfreezeGC(state);
2020-10-28 05:16:30 +00:00
}
CValue cosmoB_print(CState *state, int nargs, CValue *args) {
2020-10-28 05:16:30 +00:00
for (int i = 0; i < nargs; i++) {
CObjString *str = cosmoV_toString(state, args[i]);
printf("%s", cosmoO_readCString(str));
}
printf("\n");
return cosmoV_newNil(); // print doesn't return any args
2020-10-28 05:16:30 +00:00
}