Forum > General
Calling procedure of library via a script ?
skalogryz:
--- Quote from: marcov on July 14, 2014, 02:03:49 pm ---But calling code in a string is near impossible.
--- End quote ---
But that's scripting task. That's what PascalScript is doing right now - not 100% Pascal compatible, but at least could do the trick.
However, using a pascal script or a built-in compiler would be to sluggish and an over-engineering for the task of exporting functions.
--- Quote from: Fred vS on July 14, 2014, 01:33:35 pm ---That library uses AggPas and i want to find a trick to not export all the AggPas functions...
So if the developer want to use some AggPas procedures, he can call it via a variable.
--- End quote ---
I certainty recommend the following:
* export all the AggPas libraries, and a way to determine what is the AggPas library version number. The version number will allow to identify what functions and what parameters are available.
* do not require a developer to use exported functions. If they find the need to use AggPas function directly they could always load the function reference in run-time.
skalogryz:
Another alternative:
--- Code: ---procedure RunProc(const nm: string; const params: array of const)
begin
if (nm = 'one_of_library_procedure') and length(params=3) then
one_of_library_procedure ( params[0], params[1], params[2])
else if nm = 'another_library_procedure') and length(params=2) then
another_library_procedure ( params[0], params[1] )
...
end;
--- End code ---
completely eliminates a need of building and parsing of "the call string".
marcov:
--- Quote from: skalogryz on July 14, 2014, 02:23:43 pm ---
--- Quote from: marcov on July 14, 2014, 02:03:49 pm ---But calling code in a string is near impossible.
--- End quote ---
But that's scripting task. That's what PascalScript is doing right now - not 100% Pascal compatible, but at least could do the trick.
--- End quote ---
If Fred was asking for ways to let the user plug-in or parametrize the program with code, I'd steer him in the direction of scripting.
I didn't get that impression though, so I didn't want to confuse the picture with scripting.
Fred vS:
Wow, lot ot very interesting things here... many thanks.
Now, with your help, i see better what i want and i will try to explain it.
In a normal world, when you create a library, you have to export each function/procedure you want be accessible.
Here a traditional library :
--- Code: ---library mylib;
...
begin
...
procedure proc1(x, y, z : integer); /// EXPORTED
begin
// something...
end;
procedure proc2(x : string); /// EXPORTED
begin
// something...
end;
procedure proc3(x : boolean); /// EXPORTED
begin
// something...
end;
...
export
proc1 name 'proc1';
proc2 name 'proc2';
proc3 name 'proc3';
end.
--- End code ---
You need a wrapper/header for your main program, with declaration of the exported procedures..
And your main application will use the library like this :
--- Code: ---program myprog;
uses
...
mylib, // the header of the library
...
begin
proc1(1,2,3);
proc2('yep');
proc3(false);
end.
--- End code ---
In the not classical library, only one procedure will be exported .
And that alone procedure will run script that call procedure who are part of the library, but NOT exported.
--- Code: ---library mynotnormallib;
...
begin
...
procedure proc1(x, y, z : integer); /// NOT EXPORTED
begin
// something...
end;
procedure proc2(x : string); /// NOT EXPORTED
begin
// something...
end;
procedure proc3(x : boolean); ///NOT EXPORTED
begin
// something...
end;
procedure run_lib_script(thescript : string) ; cdecl; /// THIS IS EXPORTED
begin
fpc_run_script(thescript) ; //// here run the script and HOW to DO that ?
end;
...
export
run_lib_script name 'run_lib_script'; /// only one procedure exported
end.
--- End code ---
And your main application will use the library like this :
--- Code: ---program myprog;
uses
...
mynotnormallib, // the header of the library with only one exported proc.
...
begin
run_lib_script('proc3(false)');
run_lib_script('proc2('yep')');
run_lib_script('proc1(1,2,3)');
end.
--- End code ---
Hum, is it possible ?
skalogryz:
--- Quote from: Fred vS on July 14, 2014, 08:29:19 pm ---Hum, is it possible ?
--- End quote ---
it is possible.
Navigation
[0] Message Index
[#] Next page
[*] Previous page