[Gambas-user] Scripter as a component

Brian G brian at westwoodsvcs.com
Tue Mar 23 00:35:12 CET 2021


Scripter can be a component: 

Scripter can be integrated into an application as a component to manage script/text based type plugins 

in app code the following: 

for now add: 
Public Scripter as object 
...... 
component.load(system.find("gbs3")) t 
dim cClass as Class = class.load("Scripter") 
Scripter as object = cClass.new() 

Or perhaps gbs3 could be linked to the gambas component directory /usr/share/lib/gambas3 as gb.scripter 
Then use "gb.scripter" would work or in ide just check the gb.scripter 

Then to load a text script file as a plugin do: 

Dim Pluging1 as object = Scripter("PathToScript/script",optional [Array of scripter parms], [array of data to pass to class._new()] ) 

so at it's most simple: 
Dim Plugin2 as object = Scripter(user.home &/ "Scripts/Plugin2") 
or more complicated: 
Dim Plugin2 as object = Scripter(user.home &/ "Scripts/Plugin2",["-v","-c","-w"],["Parm1 for new","Parm2 for new",...) 
Then just make calls to the plugin like this just like any other class 
Plugin2("xxxx") or Plugin2.editthis("mybuffer") etc 

the default entry point for a plugin is : _Call(...) as variant, created by scripter in place or main for plugins 
and should include the : _new(...) method 

Just like Scripts Plugins are cached 

All Project info needed is available as a read only property of the plugin 
Example: 
Plugin2.Version inside the script use $sVersion 

A plugin should/could be defined as follows as a basic example: 

#Script Version="5.9.3" 
#Script Name="AnotherTest" 
#Script Title="Plugin tester Too" 
#Script Description="This plugin is a test for the scripter too" 

Public $sParmInfo as string = "" 

Dim s As String 
Dim sSum as string= "" 
for each s in param 
sSum &= s & " , " 
next 
print $sParmInfo 
return "Sum ["&sSum&"]" 
public sub _new(...) 
dim parminfo as string = "" 
for each v as variant in param 
ParmInfo &= quote(cstr(v)) & "," 
next 
print "defined Version = "& $sVersion &" Parminfo = ";ParmInfo 
Print $sName 
$sParmInfo = parminfo 
end 

Comments and other things are welcome! 

Yes the #Script notation is new 

"Failure is the key to success; 
each mistake teaches us something" .. Morihei Ueshiba 
Brian G 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210322/459c1013/attachment.htm>


More information about the User mailing list