2021-06-21 21:02:20 +08:00
|
|
|
/*
|
2022-04-03 02:39:57 +08:00
|
|
|
* Copyright (c) 2020-2022 Thakee Nathees
|
|
|
|
* Copyright (c) 2021-2022 Pocketlang Contributors
|
2021-06-21 21:02:20 +08:00
|
|
|
* Distributed Under The MIT License
|
|
|
|
*/
|
|
|
|
|
2022-04-15 20:35:15 +08:00
|
|
|
#ifndef MODULES_H
|
|
|
|
#define MODULES_H
|
|
|
|
|
|
|
|
#include <pocketlang.h>
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2021-06-21 21:02:20 +08:00
|
|
|
|
2022-04-20 17:10:08 +08:00
|
|
|
void registerModuleIO(PKVM* vm);
|
|
|
|
void registerModulePath(PKVM* vm);
|
2022-04-22 00:07:38 +08:00
|
|
|
void registerModuleMath(PKVM* vm);
|
2021-06-21 21:02:20 +08:00
|
|
|
|
2022-04-20 17:10:08 +08:00
|
|
|
// Registers all the cli modules.
|
|
|
|
#define REGISTER_ALL_MODULES(vm) \
|
|
|
|
do { \
|
|
|
|
registerModuleIO(vm); \
|
|
|
|
registerModulePath(vm); \
|
2022-04-22 00:07:38 +08:00
|
|
|
registerModuleMath(vm); \
|
2022-04-20 17:10:08 +08:00
|
|
|
} while (false)
|
2021-06-21 21:02:20 +08:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
2022-04-20 17:10:08 +08:00
|
|
|
/* MODULES INTERNAL */
|
2021-06-21 21:02:20 +08:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
2022-04-20 17:10:08 +08:00
|
|
|
// Allocate a new module object of type [Ty].
|
|
|
|
#define NEW_OBJ(Ty) (Ty*)malloc(sizeof(Ty))
|
2021-06-28 21:47:19 +08:00
|
|
|
|
2022-04-20 17:10:08 +08:00
|
|
|
// Dellocate module object, allocated by NEW_OBJ(). Called by the freeObj
|
|
|
|
// callback.
|
|
|
|
#define FREE_OBJ(ptr) free(ptr)
|
2021-06-21 21:02:20 +08:00
|
|
|
|
2022-04-22 00:07:38 +08:00
|
|
|
// Returns the docstring of the function, which is a static const char* defined
|
|
|
|
// just above the function by the DEF() macro below.
|
|
|
|
#define DOCSTRING(fn) __doc_##fn
|
|
|
|
|
|
|
|
// A macro to declare a function, with docstring, which is defined as
|
|
|
|
// ___doc_<fn> = docstring; That'll used to generate function help text.
|
|
|
|
#define DEF(fn, docstring) \
|
|
|
|
static const char* DOCSTRING(fn) = docstring; \
|
|
|
|
static void fn(PKVM* vm)
|
|
|
|
|
2022-04-15 20:35:15 +08:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* SHARED FUNCTIONS */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
// These are "public" module functions that can be shared. Since some modules
|
|
|
|
// can be used for cli's internals we're defining such functions here and they
|
|
|
|
// will be imported in the cli.
|
|
|
|
|
2021-06-21 21:02:20 +08:00
|
|
|
bool pathIsAbsolute(const char* path);
|
2022-04-15 20:35:15 +08:00
|
|
|
|
2021-06-21 21:02:20 +08:00
|
|
|
void pathGetDirName(const char* path, size_t* length);
|
2022-04-15 20:35:15 +08:00
|
|
|
|
2021-06-21 21:02:20 +08:00
|
|
|
size_t pathNormalize(const char* path, char* buff, size_t buff_size);
|
2022-04-15 20:35:15 +08:00
|
|
|
|
2021-06-21 21:02:20 +08:00
|
|
|
size_t pathJoin(const char* from, const char* path, char* buffer,
|
|
|
|
size_t buff_size);
|
2022-04-15 20:35:15 +08:00
|
|
|
|
|
|
|
#endif // MODULES_H
|