HOw to embed newLISP?

Notices and updates
Locked
ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

HOw to embed newLISP?

Post by ale870 »

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

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

I wonder whether this is the sort of thing that Hans-Peter can do... Search for HPW's posts...!

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

Post by ale870 »

cormullion wrote: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?
--

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »


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

Post by HPW »

He means me. ;-)

But you should search for newlisp.dll or look at

http://www.alh.net/newlisp/phpbb/viewto ... ewlisp+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.
Hans-Peter

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

Post by ale870 »

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

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

Post by HPW »

>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.
Hans-Peter

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

Post by ale870 »

>2) start newLIS
P 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).
>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...).
--

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

Post by HPW »

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.
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/viewto ... ght=delphi

http://www.alh.net/newlisp/phpbb/viewto ... 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.
Hans-Peter

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

Post by ale870 »

Thank you!
I will check them!
--

xytroxon
Posts: 296
Joined: Tue Nov 06, 2007 3:59 pm
Contact:

Post by xytroxon »

HPW wrote:
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 ;)

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

Post by HPW »

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.
Hans-Peter

Locked