newlisp.DLL possible?

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?
HPW
Posts: 1376
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

newlisp.DLL possible?

Post by HPW »

Hello Lutz,

I would like to ask if it is possible to make a newlisp.dll where I can call
a function "eval" and pass a string containing a lisp-code.(cdecl)
This would be similar to newlisp "Direct execution mode".
It would return a string to the calling Programm.
But the DLL could then stay in memory and preserve it's memory with code and data.
Would be another powerfull option.

What do you think?
Hans-Peter

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

Post by Lutz »

This has also been requested by Steve and it is on the list of things to do. Unfortunately it is one of those features, which needs a different treatment on the Windows and UNIX platforms, and I haven't done any Windows specific development in the last two years after moving newLISP to UNIX.

You might also consider talking to newLISP via TCP/IP, this is the way the newlisp-tk frontend is doing it. If you start newLISP in demon mode with the -d option it will stay in memory with all its data, even if the connecting application exits, you can reconnect and all data are still there.

This would also be a platform independent solution and you can have newLISP running on a different computer on the network/internet.

Anyway I will look into a DLL mode when I have a little bit more time.

Lutz

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

Post by HPW »

If you start newLISP in demon mode with the -d option it will stay in memory with all its data


Have not thought about that. Also interesting. I will give it a try. But direct call would be also nice.
Hans-Peter

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

Post by HPW »

Note, that the demon mode only works correctly on LINUX and BSD systems. On Win32 based systems newLISP may not be able to reconnect at all times.


Taken from the doc. Seems not so good for Win32 systems! :-((
Hans-Peter

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

Post by Lutz »

the problem is with exiting, sometimes on Windows when the client application exits, the demon will receive an exception and exit too. On my system it has never occured again since I installed XP, and I check this feature with every build. I suspect it was only true on Windows 2000.

Give it a try! You can quickly check it out with the telnet command under Windows.

But I will look into the DLL stuff anyway.

Lutz

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

Post by HPW »

But I will look into the DLL stuff anyway.



In December 7.4 will be released and the rest of the year I will just concentrate on bugfixes, a more comprehensive test-suite and review of the manual.


Any idea or date when the DLL-feature could get reality?
Only a question, so no pressure!
Hans-Peter

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

Post by Lutz »

I got it compiled and linked some time ago but cannot get it to work yet,

Lutz

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

Post by HPW »

When you need help with testing, let me know!
Of cource the basic function should be in place.
Hans-Peter

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

Post by Lutz »

Thanks Hans-Peter, I will look into it again the coming week and might post the files which you use to compile as a DLL, to get some help.

Here in USA we have the long Thanksgiving / holyday weekend, which started yesterday on Thursday, so I will be not very active here on the board until Monday.

Lutz

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

Post by HPW »

No problem!
Have a nice Thanksgiving.
We have the 1.Advent. :-)
Hans-Peter

adamss3
Posts: 14
Joined: Mon Oct 14, 2002 11:53 am

Post by adamss3 »

I'd be happy to help with the testing also.

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

Post by Lutz »

Thanks Steve, I know you have prpbably the most experience, when it comes to building newLISP on Windows. I'll give it another quick shot tomorrow Monday, because I didn't look at it since I wrote it mid October and sometimes after a while you see some obvious screwup. After that I'll pass it on to you.

Its a .c, .def and a makefile. The .c and .def files just get added to the usual files and the whole thing gets compiled with the new makefile_win32dll.

Lutz

adamss3
Posts: 14
Joined: Mon Oct 14, 2002 11:53 am

Post by adamss3 »

Okay. Just let me know.

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

Post by Lutz »

I (sort of ;-) got the DLL stuff to work. here is a win32dll-001.tgz in the development directory. It is largely untested and has problems, but it is a start. Read the win32dll.readme first.


Lutz

adamss3
Posts: 14
Joined: Mon Oct 14, 2002 11:53 am

Post by adamss3 »

Okay. I'll download it and start to work with it.

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

Post by Lutz »

Think I got everything working, a little change was necessary to avoid printing to the console and return the error string from the DLL instead. I still want to make some other changes and then we will have a new development release on Wednesday.

Lutz

adamss3
Posts: 14
Joined: Mon Oct 14, 2002 11:53 am

Post by adamss3 »

Okay. If you post those changes or email them to me, I can still do some testig.

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

Post by HPW »

I hope we then get the compiled DLL (for the people without the C-compiler).
The readme is promising.
Hans-Peter

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

Post by Lutz »

There is a newlisp_7311.tgz in the development directory, which has just the changes and additional files for making a DLL.

Don't forget to 'make clean' between making the newlisp.exe and newlisp.dll. I n a later step we can try to make a combined newlisp.exe which also can serve as a DLL.

Lutz

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

Post by HPW »

>Don't forget to 'make clean' between making the newlisp.exe and newlisp.dll.

I forgot it! :-)

Some first observation:

(get-string (dllEvalStr "(string(main-args))"))

gives a crash. I assume a DLL can not have main-args.

(get-string (dllEvalStr "(load "test1.lsp")"))

gives a crash. Maybe the double-quotes.

(get-string (dllEvalStr "(load \"test1.lsp\")"))

returns "true" but does not evaluate the expression inside the lsp "(setq a10)".
Hans-Peter

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

Post by Lutz »

There is a newlisp_7312.tgz in the development directory, it takes care of crashing in 'main-args' and 'print', both are now suppressed and will be ignored in DLL's. newlisp.dll now passes the QA suite which is not 100% but tests most features of newLISP.

Certain math exceptions i.e. (sqrt -1) result in a correct result of 'NaN', but the DLL pops up a Windows messge box, which has to be acknowledged.

Lutz

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

Post by HPW »

Yep, in 7.3.12 problem with main-args is solved.

But this remains:

(get-string (dllEvalStr "(load "test1.lsp")"))

gives a crash. Maybe the double-quotes.

(get-string (dllEvalStr "(load \"test1.lsp\")"))

returns "true" but does not evaluate the expression inside the lsp "(setq a 10)".

Here a remains nil.
Hans-Peter

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

Post by HPW »

As a quick hack I put together a neobook-plugin (delphi) for newlisp.
(hpwNewLISP.nbp 33KB Interface-DLL binded into neobook runtime)

In the past I have made some free plugins for the authoring package neobook.
I have a plugin running to call corman DLL's.

http://hpwickern.bei.t-online.de/anmeld ... obook.html

I upload a demo-exe to my plugin-page:

http://hpwickern.bei.t-online.de/anmeld ... ewLISP.zip

Question: Is it in the interest of newLisp to release this to the neobook community to spread the word about newlisp to more people?
Hans-Peter

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

Post by Lutz »

Remember that all code you execute runs in the environment of newlisp.dll. After loading you 'test1.lsp' which has (setq a 10) do a:

(get-string (dllEvalStr "a")) => "10"

Also, instead of:

(get-string (dllEvalStr "(load \"test1.lsp\")"))

you can also do for less quote clutter:

(get-string (dllEvalStr {(load "test1.lsp")}))

About the crash:

When putting "(load "test.lsp")" as argment to dllEvalStr, it really receives 3 args: "(load " , test.lsp and ")". This will mess up the call stack in the DLL, where the function expects only one argument. Fixing this would require a lot of overhead when importing functions. Right now imported functions in newLISP are very fast.

When using the DLL from other Win32 applications, this will not be an issue, as all of these to extensive checking and declaring.

In newLISP it is always recommended to put wrappers around imported functions to check for the right type and number of args if these get exposed to users.

The next version will also have fix from Steve/adamss3 for the popup problem with FP exceptions.

Lutz

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

Post by HPW »

>Remember that all code you execute runs in the environment of newlisp.dll. After loading you 'test1.lsp' which has (setq a 10) do a:

Of cource you are right. Have not thought much before posting.
Thanks for clearing. Nice advice for less quote clutter.

Seems to be another great thing with the DLL feature.
I like it very much.
Hans-Peter

Post Reply