ScriptBasic was created as an embedded scripting engine. The console interpreter and web server are examples of using the ScriptBasic API. C# is able to call C functions. The host language can get /set variables and call functions.
The script I wrote to get tenant names is good example how you could use ScriptBasic for missing functionality.
ScriptBasic is open source with a MIT Common license. It is commercially used primarily by industrial controllers as its scripting engine.
ScriptBasic runs on Windows (32/64 bit) and Linux.
using System;
using System.Runtime.InteropServices;
class Program
{
// Import the Add function from the C DLL
[DllImport("Example.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int Add(int a, int b);
static void Main()
{
int result = Add(5, 3);
Console.WriteLine($"Result: {result}"); // Output: Result: 8
}
}
This C example is calling the ScriptBasic DLL (libcriba.dll) to execute a script. All of the ScriptBasic extension modules are available from within the called embedded script.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include "scriba.h"
__declspec(dllexport) int sb(char * ScriptName, char * ScriptArgs)
{
pSbProgram pProgram;
pProgram = scriba_new(malloc,free);
scriba_LoadConfiguration(pProgram, "C:\\Windows\\SCRIBA.INI");
scriba_SetFileName(pProgram, ScriptName);
scriba_LoadSourceProgram(pProgram);
scriba_Run(pProgram, ScriptArgs);
scriba_destroy(pProgram);
return(0);
}
All of the examples I have posted could be run as a call to ScriptBasic from within your C# program.