65 lines
1.5 KiB
C
65 lines
1.5 KiB
C
/**
|
|
* Copyright (c) 2026 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#pragma once
|
|
#include "script/module/modulebase.h"
|
|
#include "script/scriptproto.h"
|
|
#include "console/console.h"
|
|
|
|
static scriptproto_t MODULE_CONSOLE_PROTO;
|
|
|
|
moduleBaseFunction(moduleConsolePrint) {
|
|
char_t buf[512];
|
|
char_t msg[4096];
|
|
size_t msgLen = 0;
|
|
|
|
for(jerry_length_t i = 0; i < argc; ++i) {
|
|
jerry_value_t strVal = jerry_value_to_string(args[i]);
|
|
moduleBaseToString(strVal, buf, sizeof(buf));
|
|
jerry_value_free(strVal);
|
|
|
|
size_t partLen = strlen(buf);
|
|
if(msgLen + partLen + 1 < sizeof(msg)) {
|
|
stringCopy(msg + msgLen, buf, sizeof(msg) - msgLen);
|
|
msgLen += partLen;
|
|
}
|
|
|
|
if(i + 1 < argc && msgLen + 1 < sizeof(msg)) {
|
|
msg[msgLen++] = '\t';
|
|
msg[msgLen] = '\0';
|
|
}
|
|
}
|
|
|
|
consolePrint("%s", msg);
|
|
return jerry_undefined();
|
|
}
|
|
|
|
moduleBaseFunction(moduleConsoleGetVisible) {
|
|
return jerry_boolean(CONSOLE.visible);
|
|
}
|
|
|
|
moduleBaseFunction(moduleConsoleSetVisible) {
|
|
moduleBaseRequireArgs(1);
|
|
CONSOLE.visible = moduleBaseArgBool(0);
|
|
return jerry_undefined();
|
|
}
|
|
|
|
static void moduleConsole(void) {
|
|
scriptProtoInit(
|
|
&MODULE_CONSOLE_PROTO, "Console",
|
|
sizeof(uint8_t), NULL
|
|
);
|
|
|
|
scriptProtoDefineStaticFunc(
|
|
&MODULE_CONSOLE_PROTO, "print", moduleConsolePrint
|
|
);
|
|
scriptProtoDefineStaticProp(
|
|
&MODULE_CONSOLE_PROTO, "visible",
|
|
moduleConsoleGetVisible, moduleConsoleSetVisible
|
|
);
|
|
}
|