Uniot Core
0.9.0
Loading...
Searching...
No Matches
uniot::unLisp Class Reference

#include <unLisp.h>

Inheritance diagram for uniot::unLisp:
[legend]

Public Member Functions

TaskScheduler::TaskPtr getTask ()
 Get the task associated with Lisp evaluation.
 
TaskScheduler::TaskPtr getCleanupTask ()
 
bool isCreated ()
 Check if the Lisp machine has been created.
 
bool taskIsRunning ()
 Check if the Lisp evaluation task is currently running.
 
size_t memoryUsed ()
 Get the amount of memory used by the Lisp machine.
 
void runCode (const Bytes &data, LispStartReason reason=LispStartReason::Received)
 Run Lisp code in the interpreter.
 
void setStartHook (LispStartHook hook)
 Set the hook called when a script starts.
 
void setStopHook (LispStopHook hook)
 Set the hook called when a script stops.
 
unLisp * pushPrimitive (Primitive *primitive)
 Add a new primitive function to the Lisp environment.
 
void serializePrimitives (CBORObject &obj)
 Serialize all registered primitive functions to CBOR format.
 
const Bytes & getLastCode ()
 Get the last executed Lisp code.
 
void cleanLastCode ()
 Clear the stored last executed code.
 
virtual void onEventReceived (unsigned int topic, int msg) override
 Event handler for received events.
 
- Public Member Functions inherited from uniot::EventListener< unsigned int, int, Bytes >
virtual ~EventListener ()=default
 Virtual destructor.
 
virtual type_id getTypeId () const override
 Get the type ID of this class for RTTI.
 
EventListener * listenToEvent (unsigned int topic)
 Subscribe to events of a specific topic.
 
EventListener * stopListeningToEvent (unsigned int topic)
 Unsubscribe from events of a specific topic.
 
bool isListeningToEvent (unsigned int topic)
 Check if this listener is subscribed to a specific topic.
 
virtual ~EventListener ()=default
 Virtual destructor.
 
virtual type_id getTypeId () const override
 Get the type ID of this class for RTTI.
 
EventListener * listenToEvent (unsigned int topic)
 Subscribe to events of a specific topic.
 
EventListener * stopListeningToEvent (unsigned int topic)
 Unsubscribe from events of a specific topic.
 
bool isListeningToEvent (unsigned int topic)
 Check if this listener is subscribed to a specific topic.
 
- Public Member Functions inherited from uniot::EventEmitter< unsigned int, int, Bytes >
virtual ~EventEmitter ()=default
 Virtual destructor to ensure proper cleanup of derived classes.
 
void emitEvent (unsigned int topic, int msg)
 Emits an event to all registered event buses.
 
virtual ~EventEmitter ()=default
 Virtual destructor to ensure proper cleanup of derived classes.
 
void emitEvent (unsigned int topic, int msg)
 Emits an event to all registered event buses.
 
- Public Member Functions inherited from uniot::EventEntity< T_topic, T_msg, T_data >
virtual ~EventEntity ()
 Destructor - disconnects from all connected EventBus instances.
 
bool sendDataToChannel (T_topic channel, T_data data)
 Sends data to a specific channel on all connected EventBus instances.
 
void receiveDataFromChannel (T_topic channel, DataChannelCallback callback)
 Receives data from a specific channel on all connected EventBus instances.
 
- Public Member Functions inherited from uniot::Singleton< unLisp >
 Singleton (const Singleton &)=delete
 Copy constructor is deleted to prevent duplicating the singleton instance.
 
Singleton & operator= (const Singleton &)=delete
 Assignment operator is deleted to prevent duplicating the singleton instance.
 

Friends

class Singleton< unLisp >
 

Additional Inherited Members

- Public Types inherited from uniot::EventEntity< T_topic, T_msg, T_data >
using DataChannelCallback = std::function<void(unsigned int, bool, T_data)>
 Callback type for handling data received from channels.
 
- Static Public Member Functions inherited from uniot::Singleton< unLisp >
static unLisp & getInstance ()
 Gets the singleton instance of the derived class.
 
- Protected Member Functions inherited from uniot::EventEntity< T_topic, T_msg, T_data >
bool connectUnique (EventBus< T_topic, T_msg, T_data > *eventBus)
 Connects to an EventBus instance if not already connected.
 
- Protected Member Functions inherited from uniot::Singleton< unLisp >
 Singleton ()=default
 Default constructor is protected to prevent instantiation outside of derived classes.
 
 ~Singleton ()=default
 Default destructor is protected to prevent deletion through base class pointer.
 
- Protected Attributes inherited from uniot::EventEntity< T_topic, T_msg, T_data >
IterableQueue< EventBus< T_topic, T_msg, T_data > * > mEventBusQueue
 Queue of EventBus instances this entity is connected to.
 

Member Function Documentation

◆ cleanLastCode()

void uniot::unLisp::cleanLastCode ( )
inline

Clear the stored last executed code.

◆ getCleanupTask()

TaskScheduler::TaskPtr uniot::unLisp::getCleanupTask ( )
inline

◆ getLastCode()

const Bytes & uniot::unLisp::getLastCode ( )
inline

Get the last executed Lisp code.

Return values
BytesThe last executed code

◆ getTask()

TaskScheduler::TaskPtr uniot::unLisp::getTask ( )
inline

Get the task associated with Lisp evaluation.

Return values
TaskScheduler::TaskPtrThe task pointer for the Lisp evaluation

◆ isCreated()

bool uniot::unLisp::isCreated ( )
inline

Check if the Lisp machine has been created.

Return values
trueThe Lisp machine exists
falseThe Lisp machine does not exist

◆ memoryUsed()

size_t uniot::unLisp::memoryUsed ( )
inline

Get the amount of memory used by the Lisp machine.

Return values
memoryUsedSize in bytes of memory used

◆ onEventReceived()

virtual void uniot::unLisp::onEventReceived ( unsigned int topic,
int msg )
inlineoverridevirtual

Event handler for received events.

This method processes events directed to the Lisp environment, particularly handling incoming events from the application.

Parameters
topicThe topic of the received event
msgThe specific message type

Implements uniot::EventListener< unsigned int, int, Bytes >.

◆ pushPrimitive()

unLisp * uniot::unLisp::pushPrimitive ( Primitive * primitive)
inline

Add a new primitive function to the Lisp environment.

Parameters
primitivePointer to the primitive function
Return values
unLisp*Pointer to the unLisp instance

◆ runCode()

void uniot::unLisp::runCode ( const Bytes & data,
LispStartReason reason = LispStartReason::Received )
inline

Run Lisp code in the interpreter.

This method creates a fresh Lisp machine if needed, stores the code, refreshes event queues, evaluates the code, and manages machine lifecycle.

Parameters
dataThe Lisp code to execute as a byte array

◆ serializePrimitives()

void uniot::unLisp::serializePrimitives ( CBORObject & obj)
inline

Serialize all registered primitive functions to CBOR format.

This allows the runtime to expose information about available primitives to client applications or documentation systems.

Parameters
objCBOR object to populate with primitive information

◆ setStartHook()

void uniot::unLisp::setStartHook ( LispStartHook hook)
inline

Set the hook called when a script starts.

Runs after the interpreter is built and its primitives are registered, but before the script is evaluated, so a peripheral prepared here is ready for the first pass.

Keep it short: it runs synchronously, and the script waits on it. Move anything heavy out with Uniot.setImmediate() – see setStopHook(), where this matters most.

Parameters
hookCallback receiving why the script started

◆ setStopHook()

void uniot::unLisp::setStopHook ( LispStopHook hook)
inline

Set the hook called when a script stops.

Runs before the interpreter is destroyed, for every reason a script can stop: it finished, it was replaced, it was cleared, or it failed.

Keep it short, and keep it especially short for LispStopReason::Failed. That case is reached from the interpreter's error printer, while lisp_eval() is still unwinding, on a stack already close to the limit the eval-stack budget guards – do the minimum needed to leave the hardware safe, and hand the rest to Uniot.setImmediate() so it runs on a fresh stack from the scheduler.

Parameters
hookCallback receiving why the script stopped

◆ taskIsRunning()

bool uniot::unLisp::taskIsRunning ( )
inline

Check if the Lisp evaluation task is currently running.

Return values
trueThe task is running (attached)
falseThe task is not running

Friends And Related Symbol Documentation

◆ Singleton< unLisp >

friend class Singleton< unLisp >
friend

The documentation for this class was generated from the following file: