Begin refactor.
This commit is contained in:
24
src/script/api/io.c
Normal file
24
src/script/api/io.c
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "io.h"
|
||||
|
||||
scripterreturn_t _scriptPrint(scriptercontext_t *ctx) {
|
||||
duk_push_string(ctx, " ");
|
||||
duk_insert(ctx, 0);
|
||||
duk_join(ctx, duk_get_top(ctx) - 1);
|
||||
printf("%s\n", duk_safe_to_string(ctx, -1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
void scriptsApiIo(scripter_t *scripter) {
|
||||
scripterDefineMethod(scripter,
|
||||
SCRIPT_IO_PRINT_NAME,
|
||||
SCRIPT_IO_PRINT_ARGS,
|
||||
&_scriptPrint
|
||||
);
|
||||
}
|
15
src/script/api/io.h
Normal file
15
src/script/api/io.h
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright (c) 2021 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
#include "../scripter.h"
|
||||
|
||||
/** Print */
|
||||
#define SCRIPT_IO_PRINT_NAME "print"
|
||||
#define SCRIPT_IO_PRINT_ARGS SCRIPTER_VARIABLE_ARGUMENT_COUNT
|
||||
scripterreturn_t _scriptPrint(scriptercontext_t *ctx);
|
||||
|
||||
void scriptsApiIo(scripter_t *scripter);
|
@ -17,6 +17,7 @@ void scripterInit(scripter_t *scripter, engine_t *engine) {
|
||||
duk_put_global_string(scripter->context, SCRIPTER_SELF_NAME);
|
||||
|
||||
// Inject API
|
||||
scriptsApiIo(scripter);
|
||||
}
|
||||
|
||||
void scripterDispose(scripter_t *scripter) {
|
||||
|
@ -6,7 +6,27 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "../libs.h"
|
||||
#include "api/io.h"
|
||||
#include "../engine/engine.h"
|
||||
|
||||
/** Implies that the arguments the function will take is variable */
|
||||
#define SCRIPTER_VARIABLE_ARGUMENT_COUNT DUK_VARARGS
|
||||
|
||||
/** Global context defintion of the pointer referring back to the scripter */
|
||||
#define SCRIPTER_SELF_NAME "__scripter"
|
||||
|
||||
/** Type forwarders */
|
||||
typedef duk_context scriptercontext_t;
|
||||
typedef duk_ret_t scripterreturn_t;
|
||||
|
||||
typedef struct {
|
||||
duk_context *context;
|
||||
engine_t *engine;
|
||||
void *user;
|
||||
} scripter_t;
|
||||
|
||||
typedef scripterreturn_t scriptermethod_t(scriptercontext_t *context);
|
||||
|
||||
/**
|
||||
* Initialize the scripter engine.
|
||||
|
Reference in New Issue
Block a user