Interaction with the environment
Most operations are directed towards the scripting engine, that is - environment makes a function call and scripting engine handles it. For everything else, there are callbacks.
Memory allocation
- sgs_MemFunc must be specified in creation of the scripting engine context
- sgs_MemFunc (re)allocates and frees memory
- unlike realloc, if size = 0, this function must return NULL
- sgs_DefaultMemFunc is the sample implementation
- the expected behavior is same as for sgs_Memory
Output
- sgs_MsgFunc and sgs_OutputFunc are responsible for piping the outputs to their destinations
- they can be set at any moment after the creation of the scripting engine context
- sgs_MsgFunc takes the following arguments:
- void* data - the user data pointer
- sgs_Context* C - the scripting engine context
- int type - the debug type (SGS_INFO, SGS_WARNING etc.)
- const char* message - the debug message
- sgs_StdMsgFunc(_NoAbort) are the sample implementations
- sgs_OutputFunc takes the following arguments:
- void* data - the user data pointer
- sgs_Context* C - the scripting engine context
- const void* ptr - the data to write
- sgs_SizeVal size - the size of data to write
- sgs_StdOutputFunc is the sample implementation
Execution notifications
- sgs_HookFunc must be set to retrieve events of that kind
- it can be set at any moment after the creation of the scripting engine context
- sgs_HookFunc takes the following arguments:
- void* data - the user data pointer
- sgs_Context* C - the scripting engine context
- int event - the event that occured, can be one of these values:
- SGS_HOOK_ENTER - function was entered
- SGS_HOOK_EXIT - function was exited
- SGS_HOOK_STEP - instruction is about to be executed
- SGS_HOOK_PAUSE - context was paused
- SGS_HOOK_CONT - context was resumed
- SGS_HOOK_CREAT - context was created (empty, no state copy)
- SGS_HOOK_CFORK - context was forked (full state copy)
- SGS_HOOK_CFREE - context was freed