PDA

View Full Version : Script plugins



Michael Hartlef
11-03-2008, 22:59
Hi folks,

thanks to Eros and his super duper fast development I asked for a feature today at work and now, well see yourself.
Btw. Eros, I need a new Ferrari. Any chance to have it delivered by the weekend? ;D

You need the latest release to run this. It's about how to realize script plugins. Here is some sample code (which is attached too):




' Script plugin sample by Michael Hartlef

uses "Console"
uses "File"

'include %app_sourcepath%+"\plugins\*.tbasicc" <= this does not work,
#include ".\plugins\*.tbasicc" ' this works

Dim MyList() As String
Dim nFiles As Long
dim i,c as long
dim funcname as string
Dim Result As Long

'Get the list of files inside the plugins folder
nFiles = DIR_ListArray(MyList, app_scriptpath+"plugins\", "*.tbasicc", %FILE_ADDPATH)

console_writeline("The plugin directory contains "+nfiles+" files.")
'Now loop through all the files and call a certain function
for i = 1 to nFiles
'Get the function name
funcname = FILE_PATHSPLIT(mylist(i), %Path_File)+"_Func"
'Call the function if it does exist
if function_exists(funcname) then
console_writeline(crlf+"calling "+funcname+"..."+crlf)
call funcname to result
endif
next

console_writeline(CRLF+"Press any key...")
console_waitkey




Here is now the code for plugin1 inside the plugins folder




' Plugin1
function plugin1_Func()
console_writeline("Hello from plugin 1")
end function



And of course, plugin number 2




' Plugin2
function plugin2_Func()
console_writeline("Hello from plugin 2")
console_writeline("Isn't that great? YES!!!!")
end function



It is damn easy. Or?

Cu
Michael

ErosOlmi
11-03-2008, 23:14
'include %app_sourcepath%+"\plugins\*.tbasicc" <= this does not work,
#include ".\plugins\*.tbasicc" ' this works



Thanks for the example showing new facilities ;)

#INCLUDE statement is expanded at pre-parsing time. At that time I've no yet string expression evaluation active so I cannot evaluate the string expression representing the include file. In any case, included files can be specified with relative path as in your example. I will try to improve this behave.

PS:
this is for you: http://www.geekologie.com/2007/10/24/ferrari-segway.jpg
Go slow!

Michael Hartlef
11-03-2008, 23:19
Cool, I love these devices. Where is the trunk to store the booze? ;D

ErosOlmi
11-03-2008, 23:23
Michael,

I was thinking about a version of CALL that automatically executes a FUCNTION_Exists, and if not just jump to next statement (line).
This should speed up operations when it is not needed to be sure that function really exists.

What do you think?
Eros

Michael Hartlef
11-03-2008, 23:27
Sure, allways nice to have. But keep the old call behaviour/function too.

ErosOlmi
11-03-2008, 23:35
Yes, of course.

Done. New function is: CALL_IFEXISTS FuncNameStringExpression[params, ...] [TO Variable]
Will be present in next release. If someone have better syntax/name, let me know.

Ciao
Eros

Michael Hartlef
11-03-2008, 23:44
No, sounds logical. Keep it.

Petr Schreiber
12-03-2008, 00:01
Nice stuff,

it will have very wide use, that is sure. Maybe CALL_IfExists could return TRUE/FALSe value too.
I will experiment with it tommorow.


Thanks Eros!,
Petr

ErosOlmi
12-03-2008, 00:16
Maybe CALL_IfExists could return TRUE/FALSe value too.


Perfect!

kryton9
12-03-2008, 00:37
Wow another incredible request and implementation!! What a great idea!
You guys are amazing!!