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-02-03 19:43:26 +00:00
|
|
|
- object library
|
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
|
|
|
|
2021-02-03 19:43:26 +00:00
|
|
|
/* loads the base object library, including:
|
|
|
|
- object.ischild or <obj>:ischild()
|
2021-02-10 23:10:03 +00:00
|
|
|
- object.__proto (allows grabbing and setting proto objects)
|
2021-02-03 19:43:26 +00:00
|
|
|
*/
|
|
|
|
COSMO_API void cosmoB_loadObjLib(CState *state);
|
|
|
|
|
2021-02-10 23:10:03 +00:00
|
|
|
/* loads the os library, including:
|
|
|
|
- os.read()
|
2021-03-20 06:02:13 +00:00
|
|
|
- os.system()
|
2021-02-10 23:10:03 +00:00
|
|
|
- os.time()
|
|
|
|
*/
|
2023-08-25 04:36:32 +00:00
|
|
|
COSMO_API void cosmoB_loadOS(CState *state);
|
2021-02-10 23:10:03 +00:00
|
|
|
|
2021-01-25 21:04:16 +00:00
|
|
|
/* loads the base string library, including:
|
2021-02-03 19:43:26 +00:00
|
|
|
- string.sub & <string>:sub()
|
|
|
|
- stirng.find & <string>:find()
|
|
|
|
- string.split & <string>:split()
|
|
|
|
- string.byte & <string>:byte()
|
|
|
|
- string.char & <string>:char()
|
2021-02-14 01:07:47 +00:00
|
|
|
- string.rep & <string>:rep()
|
2021-01-25 21:04:16 +00:00
|
|
|
|
2023-02-09 18:32:48 +00:00
|
|
|
The base proto object for strings is also set, allowing you to invoke the string.* api through
|
|
|
|
string objects, eg.
|
2021-01-25 21:04:16 +00:00
|
|
|
`"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
|
2021-02-15 20:00:26 +00:00
|
|
|
- math.tan
|
2021-01-29 21:45:24 +00:00
|
|
|
*/
|
|
|
|
COSMO_API void cosmoB_loadMathLib(CState *state);
|
|
|
|
|
2021-02-03 19:43:26 +00:00
|
|
|
/* loads the vm library, including:
|
2021-01-25 21:04:16 +00:00
|
|
|
- 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())
|
2023-06-02 00:04:12 +00:00
|
|
|
- printing closure disassemblies (vm.disassemble())
|
2021-01-25 21:04:16 +00:00
|
|
|
|
|
|
|
for this reason, it is recommended to NOT load this library in production
|
|
|
|
*/
|
2021-02-03 19:43:26 +00:00
|
|
|
COSMO_API void cosmoB_loadVM(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
|
|
|
|
2023-02-09 18:32:48 +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
|