How to call newLisp functions in DLL but not using Eval

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?
Locked
ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

How to call newLisp functions in DLL but not using Eval

Post by ale870 »

Hi,

I'm working on a framework and I need to call newLisp code. My problem is I need to call functions in a very fast way (I'm trying to use newLisp in a game framework).

Ok, I will try to be more clear:

1) I open newlisp.dll

2) I get a reference to newlispEvalStr

3) First phase: I evaluate a big script to let newLisp compile it (newlispEvalStr(...my big script...).

4) Second phase: I need to call the functions I already stored in the previous step. So for example I need: newlispEvalStr("(calc-sum 1 2 3 4 5)") and imagine that the function calc-sum was previously stored/compiled in the DLL in the point 3-first phase.

Well, my problem is step 4 (second phase) must be called at runtime, when my game is running, so it could run at 60 calls per second (at least).
When I use newlispEvalStr, newLisp precompile the code everytime I use it. Instead it could be useful a function (similar to newlispEvalStr) but to call a newLisp function directly, without recompilation (like newLisp interpreter do).
I could even use pointers, etc... to get references to such functions. And consider I need only to call functions (maybe in namespaces).

This is very important for me, since performance are a key-point in a gaming system.

One thing more: don't care about the programing language I use, in fact I could adapt any example you have. Now I'm working in Pure Basic (but even C or Pascal/Delphi is good for me).

Thank you for your help!


Can you help me?
--

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

Is the interpretation of the newlispEvalStr("(calc-sum 1 2 3 4 5)") too expensive for you?
I think newLISP is very fast on such a one-liner.

Not sure if it is possible to get a pointer to a newLISP function to call it from outside.

Reminds me to our discussion here:

http://www.alh.net/newlisp/phpbb/viewto ... highlight=

But that was the other way round.
Hans-Peter

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

When you eval only the function-name you get back a hex.
> setq
setq <6BD47654>
Maybe this is the memory adress?
Hans-Peter

ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

Post by ale870 »

I made some tests, and even if parsing and interpretation newLisp is quite fast, it is VERY slower than native function call.
I made a trivial test, by creating the function (define (calc-sum v1 v2)(+ v1 v2)) and I called it in a big loop inside my application (PureBasic using eval) and in a native call (inside newLisp interpreter).
Inside the interpreter is many times faster than eval (more than 100 times!).
This is a big improvement for me, since I need to call some newLisp functions inside main rendering process of the 3D environment. Consider that a game usually run at 60 FPS, it means I need to call the function 60 times per second!
So the final "delay" coming from the interpretation may affect the global game performance (plus consider that I need to call several functions, and not only one).

Thank you.
--

ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

Post by ale870 »

HPW wrote:When you eval only the function-name you get back a hex.
> setq
setq <6BD47654>
Maybe this is the memory adress?

I don't know, but even if it would be so, that one is not binary code, that I can call like a normal function (written in machine code). That address should be (I think) p-code compiled by newLisp interpreter.

I think newLisp DLL should contain a native function to recall a newLisp function and return a result (something like newLispCallFunction("function name", .... params....)).


Params could be contained in a list or other specific memory area (I don't know how newLisp works do accomplish that job).
--

ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

Post by ale870 »

Luz, is there any way to expose a function to call a function directly instead using newlispEvalString? If such function would exist, function calling could be much faster since a ricompilation would not be needed.
--

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

There is no way to make this work. The library carries/is its own interpreter environment. Function calls are made with specific data types etc..

Perhaps you should consider to go the opposite way: writing your application in newLISP and importing a GUI or whatever other library you need into newLISP.

ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

Post by ale870 »

Thank you for your help Luz. But I cannot start from the opposite way, since I need to connect to a 3D Engine that must work as Pure Basic application, furthermore I need to make some jobs VERY fast, and even if newLisp is fast, it is not as fast as a pure compiled application.
Now I'm working to let the people use newLisp power without using too many calls to "newlispEvalStr".


Thank you.
--

newBert
Posts: 156
Joined: Fri Oct 28, 2005 5:33 pm
Location: France

Post by newBert »

I think you can create a DLL from a PureBasic program and then you should use it in NewLISP. I tackled PureBasic a little for a long time, before I got on with Freestyle Basic, and I think it's possible if my memory is still good .

In any case it works with a Rebol script calling such a PureBasic DLL, but I didn't try 3D-programs (it was only a GUI-program set in a DLL by PureBasic).

P.S. : except that :
PureBasic FAQ wrote: Is it allowed to use DLLs made with PureBasic in other projects ?

Generally yes. You can make DLLs including PureBasic commands for your own projects without any restrictions. But it's not allowed to release simple "wrapper" Dlls to include PureBasic commands in other programming languages.
BertrandnewLISP v.10.7.6 64-bit on Linux (Linux Mint 20.1)

ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

Post by ale870 »

After some time I decided to take a different way: I directly mapped Pure Basic functions in my newLisp app:

Pure Basic EXE -> open nL DLL

See my last article in my blog (automatic english translation is included):

http://translate.google.com/translate?h ... a-newlisp/

Original (italian) article:

http://newlisp.wordpress.com/2008/11/14 ... a-newlisp/

I always need to use newlispEval but much lesser than before.

Thank you!
--

Locked