Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Dec 28, 2012 4:21:11 GMT 1
I hope this introduction of ScriptBasic as an API based scripting engine has generated some interest in new ways to add functionality to your BaCon applications. I have attached a .chm version of the ScriptBasic developers guide which is also online here. Hint: If your looking for a working example how a SB API function is used, look at the scriba source.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Aug 25, 2013 21:56:49 GMT 1
I updated my BaCon embedding ScriptBasic example. Of all the BASIC host languages I have done embedding examples for, BaCon has been the easiest. (SB's little brother) The executable is only 60 KB in size for this example. FYI: A BaCon PRINT "Hello World" is 55 KB.
sbembed.bac
' BaCon embedding ScriptBasic example
PRAGMA OPTIONS -I/home/jrs/sb/source PRAGMA LDFLAGS scriba pthread PRAGMA INCLUDE scriba.h getopt.h
PROTO scriba_destroy scriba_DestroySbArgs
DECLARE pProgram TYPE pSbProgram DECLARE ReturnData TYPE SbData DECLARE ArgData TYPE pSbData DECLARE bob TYPE pSbData
' Create ScriptBasic object and load script pProgram = scriba_new(malloc, free) ok = scriba_LoadConfiguration(pProgram, "/home/jrs/sb/sb22/bin/basic.conf") ok = scriba_SetFileName(pProgram, "sbembed.sb") ok = scriba_LoadSourceProgram(pProgram) ok = scriba_Run(pProgram,"")
' Call SUB pass no arguments t_sub_1 = scriba_LookupFunctionByName(pProgram, "main::t_sub_1") ok = scriba_Call(pProgram, t_sub_1) PRINT
' Retrieve SB global variable vsn = scriba_LookupVariableByName(pProgram, "main::bob") ok = scriba_GetVariable(pProgram, vsn, &bob) PRINT "bob var type: ", bob[0].type PRINT "bob var size: ", bob[0].size PRINT "bob var value: ", bob[0].v.l PRINT
' Call SUB pass SB global as an argument t_sub_2 = scriba_LookupFunctionByName(pProgram, "main::t_sub_2") ok = scriba_CallArg(pProgram, t_sub_2, "i", bob[0].v.l) PRINT
' Call script FUNCTION passing arguments and returning a result sb_long = 123 sb_real = .321 sb_str$ = "ScriptBasic" t_func_3 = scriba_LookupFunctionByName(pProgram, "main::t_func_3") ArgData = scriba_NewSbArgs(pProgram, "i r s", sb_long, sb_real, sb_str$) ok = scriba_CallArgEx(pProgram, t_func_3, &ReturnData, 3, ArgData) scriba_DestroySbArgs(pProgram, ArgData, 3) PRINT "Arguments Passed: ", ReturnData.v.l
scriba_destroy(pProgram)
sbembed.sb
' Embed test script
bob = 99
SUB t_sub_1 PRINT "SUB with no arguments passed.\n" END SUB
SUB t_sub_2(this_bob) PRINT this_bob," bottles of beer on the wall.\n" this_bob -= 1 PRINT "Take one down, pass it around, ",this_bob," bottles of beer on the wall.\n" END SUB
FUNCTION t_func_3(longarg, realarg, strarg) PRINT longarg,"\n" PRINT FORMAT("%g",realarg),"\n" PRINT strarg,"\n" t_func_3 = 3 END FUNCTION
Results
jrs@laptop:~/BaCon/2302$ ./sbembed SUB with no arguments passed.
bob var type: 2 bob var size: 0 bob var value: 99
99 bottles of beer on the wall. Take one down, pass it around, 98 bottles of beer on the wall.
123 0.321 ScriptBasic Arguments Passed: 3 jrs@laptop:~/BaCon/2302$
SbData Structure
typedef struct _SbData { unsigned char type; unsigned long size; union { double d; long l; unsigned char *s; } v; } SbData, *pSbData;
// ScriptBasic data TYPE
#define SBT_UNDEF 0 #define SBT_DOUBLE 1 #define SBT_LONG 2 #define SBT_STRING 3 #define SBT_ZCHAR 4
|
|