How to write plugins for SmallBASIC?

Started by bprlhe, August 05, 2023, 12:53:27

Previous topic - Next topic

bprlhe

It seems there is no official tutorials. I found a collection of SmallBASIC plugins on Github, though. I have read some of the plugins (the main.cpp source file and the headers on include directory) but I still don't understand how it works and how to write a SmallBASIC plugin.

bplus

Neither do I, too bad about sb documentation :(
1 person likes this

J7M

Maybe I should write a little tutorial about creating plugins. But it will take some time....

In the meantime you can have a look to my Raspberry Pi plugin:
https://github.com/Joe7M/SmallBasicPIGPIO/tree/main/src
You need the following minimum set of files (can be found here: https://github.com/smallbasic/smallbasic.plugins): config.h, hashmap.cpp, hashmap.h, main.cpp, module.h, param.cpp, param.h, var.h. The Makefile in the RaspberryPi-plugin shows how to compile. In main.cpp you define all the functions and procedures. What name they have in SB and what function should be called in C. You also have to define, how many parameters the commands need.
Have a look to gpio.c. In function GPIO_Write you can see how to pass parameters with get_param_int(argc, params, NumberOfParam, DefaultValue). In function GPIO_Read a integer value is returned using v_setint(retval, Value).
Depending on the parameter you want to pass or the value you want to return, different functions have to be used. These functions are listed in param.h.

Maybe this short version helps a little bit for the moment.