newLISP Fan Club

Forum => newLISP newS => Topic started by: ale870 on February 17, 2008, 06:16:36 AM

Title: HOw to embed newLISP?
Post by: ale870 on February 17, 2008, 06:16:36 AM
Hello,



I was wondering if I could (and how?) embed newLISP interpreter in another application (windows) just like other scripting languages like LUA, AngelScript, etc...

I'm creating a 3D game using 3D Game Studio, and since this is a particular game, I wanted to embed a scripting system. So I wanted to use newLISP for modding scripting.



3DGS let me manage standard DLLs.



1) Do you think it is feasible?

2) Is it difficult?

3) How could I enchange data between my game and scripting?



Thank you!
Title:
Post by: cormullion on February 17, 2008, 10:49:34 AM
I wonder whether this is the sort of thing that Hans-Peter can do... Search for HPW's posts...!
Title:
Post by: ale870 on February 17, 2008, 01:17:38 PM
Quote from: "cormullion"I wonder whether this is the sort of thing that Hans-Peter can do... Search for HPW's posts...!


Sorry, but I don't know what is "HPW". Please help me to better explain me that?
Title:
Post by: cormullion on February 17, 2008, 01:29:04 PM
//http://www.alh.net/newlisp/phpbb/profile.php?mode=viewprofile&u=4
Title:
Post by: HPW on February 17, 2008, 01:30:14 PM
He means me. ;-)



But you should search for newlisp.dll or look at



http://www.alh.net/newlisp/phpbb/viewtopic.php?t=76&highlight=newlisp+dll



So newlisp.dll is a standard windows dll and there is a function 'newlispEvalStr' exported.

This is what you call.

This function returen a PChar-string as result.

Of cource you can add other callbacks into you code from newlisp.

Therefore newlisp imports functions from your host-app.



I have used this from various plattforms:



neobook-plugin

delphi

powerbasic

There is also a demo for Excel here on the forum.
Title:
Post by: ale870 on February 17, 2008, 02:17:02 PM
Thank you! This is a good starting point.

But  it is not for me launching simple evals. I need to startup a kind of engine, and the script should be loaded then the functions should be recalled. Let's say that newLISP environment should be statefull, and I need to configure the environment (variables, user defined functions, etc...).

Look at the concept how LUA works (or even AngelScript, or other scripting languages "embedded" in other applications).



Basically, these steps should be followed:



1) start main application (my application)

2) start newLISP engine

3) load functions in newLISP, register variables, startup needed functions to make interaction between my application and newLISP.

4) The program now is running, and there is a complete interaction back and forth from my app and newlisp (and vice-versa).



Using only the dll (using only the eval), is not the way to fully embed a language inside another one.



However, I will study the link you sent me.



Thank you!
Title:
Post by: HPW on February 17, 2008, 10:49:05 PM
>1) start main application (my application)



No problem



>2) start newLISP engine



No problem



>3) load functions in newLISP, register variables, startup needed functions to make interaction between my application and newLISP.



Depends what you mean with interaction.



 >4) The program now is running, and there is a complete interaction back and forth from my app and newlisp (and vice-versa).



There is always one leading site. There is running the main-loop of the app. And that is mostly the GUI part which is waiting for events.
Title:
Post by: ale870 on February 18, 2008, 12:50:24 AM
>2) start newLIS
QuoteP engine



No problem


Good news! Does it mean that, in this case, newLISP does NOT work as a CGI-like system (newLISP interpreter is executed->newLISP program is executed->interpreter is closed) but like a "server" (interpreter is executed and it is waiting for "commands"; it means if I set a global variable with a function, I will find that variable already set to the next function call).


Quote>3) load functions in newLISP, register variables, startup needed functions to make interaction between my application and newLISP.



Depends what you mean with interaction.



There is always one leading site. There is running the main-loop of the app. And that is mostly the GUI part which is waiting for events.


You are right. I want to startup newLISP environment like a "server". My application (the game) will "load" the scripts in newLISP environment, will setup needed variables, etc... (prepare the environment). Then my game will run, and will call newLISP specific functions to resolve A.I., vehicle movements, perform user specific activities, etc...

User (final game programmer) should be able to use newLISP to write A.I, write specific events to create a game scenario, etc...



(I don't know I if the concept is enough clear...).
Title:
Post by: HPW on February 18, 2008, 01:14:00 AM
Quoteinterpreter is executed and it is waiting for "commands"; it means if I set a global variable with a function, I will find that variable already set to the next function call.


Yes, the DLL is loaded into the workspace of your host app and remains there until shutdown. It stores the state of all variables and symbols.



When I start with newlisp.dll a long time ago, my first use was to process the return value of 'newlispEvalStr'. Over time this I realize that this was limiting the possibilitys. So I exported a function interface from my host-app and import that functions from newlisp.



The scenario works like this:



A GUI event happens and it calls 'newlispEvalStr'.

Some lisp gets executed and it optionally calls direct functions via the imported functions.

Then it returns from the 'newlispEvalStr'and the main-app is back in the main-loop.



Links to samples for delphi and powerbasic:

http://www.alh.net/newlisp/phpbb/viewtopic.php?t=168&highlight=delphi



http://www.alh.net/newlisp/phpbb/viewtopic.php?t=280&highlight=powerbasic



Of cource there is also the other concept from the newlisp-IDE.

The new java GUI and the old TCL-TK GUI works as 2 independent processes where a communication via TCP/IP is used.

You can see both processes in the tasklist.
Title:
Post by: ale870 on February 19, 2008, 02:43:34 AM
Thank you!

I will check them!
Title:
Post by: xytroxon on February 19, 2008, 02:18:20 PM
Quote from: "HPW"


Links to samples for delphi and powerbasic:


Very interesting!



Are there examples for embedding newLISP for C/C++?



Better for me if written for MinGW C  ;)
Title:
Post by: HPW on February 19, 2008, 10:46:16 PM
There were other sample listed here:



http://www.newlisp.org/index.cgi?Code_Contributions



And importing a standard lib should be not difficult.



Maybe the C/C++ experts here can give a sample.