2020-10-28 05:16:30 +00:00
|
|
|
#ifndef COSMO_BASELIB
|
|
|
|
#define COSMO_BASELIB
|
|
|
|
|
|
|
|
#include "cstate.h"
|
|
|
|
|
2021-01-20 04:54:06 +00:00
|
|
|
/* loads all of the base library, including:
|
|
|
|
- base library ("print", "assert", "type", "pcall", "loadstring", etc.)
|
2021-01-29 21:45:24 +00:00
|
|
|
- string library
|
|
|
|
- math library
|
2021-01-20 04:54:06 +00:00
|
|
|
*/
|
2020-11-13 05:04:09 +00:00
|
|
|
COSMO_API void cosmoB_loadLibrary(CState *state);
|
2021-01-25 21:04:16 +00:00
|
|
|
|
|
|
|
/* loads the base string library, including:
|
|
|
|
- string.sub
|
|
|
|
- stirng.find
|
|
|
|
- string.split
|
2021-02-02 03:07:43 +00:00
|
|
|
- string.byte
|
|
|
|
- string.char
|
2021-01-25 21:04:16 +00:00
|
|
|
|
|
|
|
The base proto object for strings is also set, allowing you to invoke the string.* api through string objects, eg.
|
|
|
|
`"hello world":split(" ")` is equivalent to `string.split("hello world", " ")`
|
|
|
|
*/
|
2021-01-20 04:54:06 +00:00
|
|
|
COSMO_API void cosmoB_loadStrLib(CState *state);
|
2021-01-25 21:04:16 +00:00
|
|
|
|
2021-01-29 21:45:24 +00:00
|
|
|
/* loads the base math library, including:
|
|
|
|
- math.abs
|
|
|
|
- math.floor
|
|
|
|
- math.ceil
|
|
|
|
*/
|
|
|
|
COSMO_API void cosmoB_loadMathLib(CState *state);
|
|
|
|
|
2021-01-25 21:04:16 +00:00
|
|
|
/* sets the base proto of all objects to the debug proto which allows for
|
|
|
|
- manipulation of the ProtoObject of objects through the '__proto' field
|
|
|
|
|
|
|
|
additionally, the vm.* library is loaded, including:
|
|
|
|
- manually setting/grabbing base protos of any object (vm.baseProtos)
|
2021-01-29 21:45:24 +00:00
|
|
|
- manually setting/grabbing the global table (vm.globals)
|
|
|
|
- manually invoking a garbage collection event (vm.collect())
|
2021-01-25 21:04:16 +00:00
|
|
|
|
|
|
|
for this reason, it is recommended to NOT load this library in production
|
|
|
|
*/
|
2020-11-13 05:04:09 +00:00
|
|
|
COSMO_API void cosmoB_loadDebug(CState *state);
|
Added CObjError, cosmoV_throw(), pcall(), and cosmoV_printError()
Errors are now handled very differently, parser errors and VM errors are now treated the same.
When cosmoV_error is called, cosmoV_throw is also called, which formats the error object and sets the panic state.
state->error now points to the latest CObjError when state->panic is true. To get a nice formatted Objection message, use
cosmoV_printError() and pass the state->error. pcall() was added to the standard base library. When called, the first argument
passed is called with the subsequent arguments given. If the call completed successfully, `true`,`nil` is returned. However
when an error occurs during the call, `false`,`<error>` is returned. Simply print the `<error>` to retrieve the error string.
2021-01-06 04:27:59 +00:00
|
|
|
|
|
|
|
#define cosmoV_typeError(state, name, expectedTypes, formatStr, ...) \
|
|
|
|
cosmoV_error(state, name " expected (" expectedTypes "), got (" formatStr ")!", __VA_ARGS__);
|
2020-10-28 05:16:30 +00:00
|
|
|
|
2021-01-02 05:06:24 +00:00
|
|
|
#endif
|