How to call newLisp functions in DLL but not using Eval

Started by ale870, November 11, 2008, 03:05:19 AM

Previous topic - Next topic

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

#1
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/viewtopic.php?t=2387&highlight=">http://www.alh.net/newlisp/phpbb/viewto ... highlight=">http://www.alh.net/newlisp/phpbb/viewtopic.php?t=2387&highlight=



But that was the other way round.
Hans-Peter

HPW

#2
When you eval only the function-name you get back a hex.


Quote
> setq

setq <6BD47654>


Maybe this is the memory adress?
Hans-Peter

ale870

#3
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

#4
Quote from: "HPW"When you eval only the function-name you get back a hex.


Quote
> 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

#5
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

#6
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

#7
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

#8
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 :
Quote from: "PureBasic FAQ" 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.
<r><I>>Bertrand<e></e></I> − <COLOR color=\"#808080\">><B>newLISP<e></e></B> v.10.7.6 64-bit <B>>on Linux<e></e></B> (<I>>Linux Mint 20.1<e></e></I>)<e></e></COLOR></r>

ale870

#9
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?hl=it&ie=UTF8&sl=it&tl=en&u=http://newlisp.wordpress.com/2008/11/14/chiamare-una-funzione-pure-basic-da-newlisp/">http://translate.google.com/translate?h ... a-newlisp/">http://translate.google.com/translate?hl=it&ie=UTF8&sl=it&tl=en&u=http://newlisp.wordpress.com/2008/11/14/chiamare-una-funzione-pure-basic-da-newlisp/



Original (italian) article:



http://newlisp.wordpress.com/2008/11/14/chiamare-una-funzione-pure-basic-da-newlisp/">http://newlisp.wordpress.com/2008/11/14 ... a-newlisp/">http://newlisp.wordpress.com/2008/11/14/chiamare-una-funzione-pure-basic-da-newlisp/



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



Thank you!
--