Recent

Author Topic: external library in pas2js file  (Read 2932 times)

krolikbest

  • Full Member
  • ***
  • Posts: 247
external library in pas2js file
« on: January 28, 2023, 08:24:22 pm »
Hi,

 i try to use some functions from my library. Declaration is as follows:
Code: Pascal  [Select][+][-]
  1.   function CalculateArm(x,y : Integer; fixedPoint : TFixedPoint; var RobotArmInfo : TRobotArmInfo; var seg : TArm) : Boolean; stdcall; external 'project1.dll';
  2.   function GetRangeOfArm(seg : TArm) : Integer; stdcall; external 'project1.dll';  

but during compilation pas2js file I get the error
Quote
unit1.pas(81,24) Error: Not supported: stdcall
I'm using win7 64bit, Lazarus 2.0.10, but I suspect that the platform has nothing to do with it. Perhaps it is a matter to pas2js engine? I did installation two years ago, so maybe since then something in pas2js has changed and this issue appears no more?

Some variables in my library are Single type and using this type in pasjs file I get also warning:
Quote
unit1.pas(76,13) Warning: Symbol "Single" is not implemented
I hope that in this case I'll be okey anyway.

Regards,

Thaddy

  • Hero Member
  • *****
  • Posts: 15159
  • Censorship about opinions does not belong here.
Re: external library in pas2js file
« Reply #1 on: January 28, 2023, 08:28:01 pm »
replace with winapi
Of course the national anthem of the U.S.A. was written by Jimi Hendrix, didn't you know that?

krolikbest

  • Full Member
  • ***
  • Posts: 247
Re: external library in pas2js file
« Reply #2 on: January 28, 2023, 08:57:44 pm »
Now it gives me Syntax error :) In Project Inspector  in Required Packages are added:
'pas2js_rtl, and 'WCL'. I'm saying this because maybe it is syntax error is related to use something else but I can't use i.e. LCL and similar..

 

PierceNg

  • Sr. Member
  • ****
  • Posts: 377
    • SamadhiWeb
Re: external library in pas2js file
« Reply #3 on: January 29, 2023, 02:54:19 am »
Code: Pascal  [Select][+][-]
  1.   function ...; stdcall; external 'project1.dll';
  2.   function ...; stdcall; external 'project1.dll';  

Perhaps it is a matter to pas2js engine? I did installation two years ago, so maybe since then something in pas2js has changed and this issue appears no more?

You mean the code worked two years ago? In web browser or with say Node?

The 'compiled' output of pas2js is Javascript source code, to be run with some Javascript engine. The well known engines are the web browsers and Node, but there are others.

Node supports calling DLLs. Not sure if this functionality is exposed to pas2js. Anyway if you can run Node you might also be able to run native-compiled Pascal program in its place and not use Node at all?

Web browsers dropped the old Netscape plugin API a few years back. Dunno if there is some new standard. Letting web browser run native code from arbitrary DLL is a security no-no in principle.

See this page: https://wiki.freepascal.org/pas2js_modules

krolikbest

  • Full Member
  • ***
  • Posts: 247
Re: external library in pas2js file
« Reply #4 on: January 29, 2023, 11:09:31 am »
Quote
You mean the code worked two years ago? In web browser or with say Node?

No, this is my first attempt at using an external library. Fortunately this is my library (for compute some trigonometric functions) so I can easily implement them into the source of the pas2js file.

PierceNg

  • Sr. Member
  • ****
  • Posts: 377
    • SamadhiWeb
Re: external library in pas2js file
« Reply #5 on: January 29, 2023, 12:18:44 pm »
No, this is my first attempt at using an external library. Fortunately this is my library (for compute some trigonometric functions) so I can easily implement them into the source of the pas2js file.

After you have it all working, you could try compiling what usually goes into the DLL into WebAssembly and use it from your pas2js program.

krolikbest

  • Full Member
  • ***
  • Posts: 247
Re: external library in pas2js file
« Reply #6 on: January 29, 2023, 12:48:37 pm »
Ok, I get the idea, compiling to wasm. I will consider this for my future projects. Currently for my few function from library I've made an extra unit in pas2js project and it works.

krolikbest

  • Full Member
  • ***
  • Posts: 247
Re: external library in pas2js file
« Reply #7 on: February 02, 2023, 11:59:54 am »
As I suspected in my first email, it is about new version of pas2js. So according to https://wiki.freepascal.org/pas2js#Releases from ver 2.1.0 (pas2js)  libraries are supported  :)

af0815

  • Hero Member
  • *****
  • Posts: 1334
Re: external library in pas2js file
« Reply #8 on: February 02, 2023, 12:48:04 pm »
So according to https://wiki.freepascal.org/pas2js#Releases from ver 2.1.0 (pas2js)  libraries are supported  :)
If i look in https://wiki.freepascal.org/pas2js_modules it is true - BUT this must be *.js Modules aka libraries ! Not normal *.so (Linux) *.dll (Windows) libraries.
regards
Andreas

krolikbest

  • Full Member
  • ***
  • Posts: 247
Re: external library in pas2js file
« Reply #9 on: February 02, 2023, 12:59:03 pm »
There is a paragraph : Using Pascal Library from Pascal. I understand it as using .so or .dll but it is highly possible that I get it wrong, have to check in near future.

 

TinyPortal © 2005-2018