Forum > General

capture apl_exec stdout

<< < (2/15) > >>

TRon:
@toby: can't oblige right now. will try again as soon as time permits.

toby:
this is the fpc header file i use - it give me complete access to all the apl commands with apl_exec - i left all the test lines (commented) that i have tried to no effect


unit libaplu;

interface

// extern void init_libapl(const char * progname, int log_startup);
procedure init_libapl(progname : ansistring; log_startup : integer); cdecl;

//extern LIBAPL_error apl_exec(const char * line_utf8);
function apl_exec(line_utf8 : ansistring) : longint; cdecl;
//function apl_exec(line_utf8 : pchar) : longint; cdecl;

//extern const char * apl_command(const char * command_utf8);
function apl_command(command_utf8 : pchar) : pchar; cdecl; // good : output is apl result
//function apl_command(command_utf8 : pchar) : longint; cdecl; // good : output is integer
//function apl_command(command_utf8 : pchar) : ansistring; cdecl; // does not worl
//function apl_command(command_utf8 : ansistring) : ansistring; cdecl; // does not work
//function apl_command(command_utf8 : ansistring) : longint; cdecl; // does not work

implementation

procedure init_libapl(progname : ansistring; log_startup : integer); cdecl; external;

function apl_exec(line_utf8 : ansistring) : longint; cdecl; external;
//function apl_exec(line_utf8 : pchar) : longint; cdecl; external;

function apl_command(command_utf8 : pchar) : pchar; cdecl; external;
//function apl_command(command_utf8 : pchar) : longint; cdecl; external;
//function apl_command(command_utf8 : pchar) : ansistring; cdecl; external;
//function apl_command(command_utf8 : ansistring) : ansistring; cdecl; external;
//function apl_command(command_utf8 : ansistring) : longint; cdecl; external;

end.

Thaddy:
AnsiString functions need wrappers because it is a Pascal string type that apl does not know about, e.g:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit libaplu;{$mode objfpc}{$H+ string=ansistring}interface{ Pascal function wrappers }procedure init_libapl(progname : string; log_startup : integer = 0);inline;function apl_exec(line_utf8 : string) : integer;inline;function apl_command(command_utf8 : string):string;inline; { external declarations , no need to use them}procedure init_libapl(progname : PChar; log_startup : longint);cdecl;external;function apl_exec(line_utf8 : pchar) : longint; cdecl; external;function apl_command(command_utf8 : pchar) : pchar; cdecl; external; implementation procedure init_libapl(progname : string; log_startup : integer);begin  init_libapl(Pchar(progname),log_startup);end; function apl_exec(line_utf8 : string) : integer;begin    Result :=apl_exec(PChar(line_utf8));end; function apl_command(command_utf8 : string) : string;var temp:Pchar;begin   temp:=apl_command(pchar(command_utf8));   setstring(Result,temp, strlen(temp));end; end.I removed nonsense declarations.
Btw: you were lucky that your own init_libapl (AnsiString) worked!! I have corrected that.
Untested, but compiles and should be OK. The cdecl is not necessary for the wrappers.

Does anybody have a libapl.dll binary? (pref 64 bit, but 32 bit is acceptable)

TRon:
Thank you for your header code Thaddy.


--- Quote from: Thaddy on January 15, 2023, 08:30:26 am ---Does anybody have a libapl.dll binary? (pref 64 bit, but 32 bit is acceptable)

--- End quote ---
Does this satisfy your needs ?

@toby:
Thanks. I got trunk compiled now. libapl Is working as expected (even though I took a bit of another route but that is besides the point).

I am able to confirm that attempting to reroute as suggested by Thaddy's assignstream example (which was my first thought as well) does indeed not work as expected. If at all possible, I would need more time to figure out how.

Thaddy:
Can you confirm my code works, the wrappers that is?


--- Quote from: TRon on January 15, 2023, 12:35:17 pm ---Thank you for your header code Thaddy.


--- Quote from: Thaddy on January 15, 2023, 08:30:26 am ---Does anybody have a libapl.dll binary? (pref 64 bit, but 32 bit is acceptable)

--- End quote ---
Does this satisfy your needs ?

--- End quote ---
Alas no, did you get it to work? Seems only the keyboard driver.
Note I am missing some unitialize call. I am sure there must be one, because the dll or shared library uses its own memory management.
Can you post the signature for that? Then I can also add that one too.
If you experience any problems with my code plz inform here, but I am quite confident that it works.

About the console output: I probably need to change the APL sourcecode to be able to capture the handles.
But that is doable.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version