PDA

View Full Version : calling newlisp from thinbasic



zak
01-11-2010, 12:10
newlisp www.newlisp.org (http://www.newlisp.org) is a script language and a small size core engine with many many modules addons , can display graphics , opengl, tk and much more, and can be called by other programs like powerbasic and vb , the following code is an adaptation of a vb6 program to load "newlisp.dll" and passing a string which contains the lisp program then reading the return result from memory.
the vb6 program can be found here near the end of this page:
http://www.newlisp.org/index.cgi?Code_Contributions
the newlisp.dll can be downloaded from here
https://sites.google.com/site/perlopengl/newlisp.rar , or install the newlisp , the dll in its folder.
the program we will pass to newlisp is a factorial program in fac.txt file in the same thinbasic code.


(define (fac n)
(if (= n 0)
1
(* n (fac (- n 1)))))
(fac 3)


you can also write lisp code in a multiline TextBox in a GUI mode.
you will notice that the program return a listing of the code before printing the results of (fac 3) and (fac 10), i do not yet how how to stop this listing. i may ask newlisp forum.

thinbasic program:


Uses "console", "File"

Declare Function dllNewlispEval Lib "newlisp.dll" Alias "newlispEvalStr" (ByVal LExpr As String) As Long
Declare Function LoadLibrary Lib "KERNEL32.DLL" Alias "LoadLibraryA" (ByVal s As String) As Long
Declare Function FreeLibrary Lib "KERNEL32.DLL" Alias "FreeLibrary" (ByVal hLibModule As DWord) As Long
Declare Function lstrLen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Long) As Long
Declare Function lstrCpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As Long) As Long

Global NewlispHandle As Long
Global outText As String

LoadNewLISP() 'loading the newlisp library

Dim inText As String
inText = FILE_Load("fac.txt")
outText = newlispEval(inText)
PrintL outText

inText = "(fac 10)"
outText = newlispEval(inText)
PrintL outText

UnloadNewLISP()
WAITKEY

Sub LoadNewLISP()
Dim mylib As String
Dim hinst As Long
mylib = "newlisp.dll"
NewlispHandle = LoadLibrary(mylib)

If NewlispHandle = 0 Then
MsgBox "NewLISP cannot be found"
End
End If
End Sub

Sub UnloadNewLISP()
FreeLibrary NewlispHandle
End Sub

Function newlispEval(LispExpression As String) As String
Dim stringlen As Integer
Dim ResHandle As Long
Dim Result As String
ResHandle = dllNewlispEval(LispExpression)
stringlen = lstrLen(ResHandle)
Result = Peek$(ResHandle, stringlen)
newlispEval = Result
End Function



links:
http://community.thinbasic.com/index.php?topic=3384.0
http://community.thinbasic.com/index.php?topic=3441.0
http://newlispfanclub.alh.net/forum/
http://newlisp.nfshost.com/benchmarks/
http://en.wikibooks.org/wiki/Introduction_to_newLISP
http://www.rhinocerus.net/forum/lang-lisp/427132-newlisp-simple-terse-well-documented.html

danbaron
02-11-2010, 09:04
[font=courier new][size=8pt]I downloaded newlisp.

No matter what I do, I cannot get the IDE to start.

:oops:
Dan

matthew
02-11-2010, 11:29
You need to have Java (http://www.java.com/en/) installed if you want to use the IDE.

zak
02-11-2010, 11:52
hello dan
as matthew said the ide needs Java Runtime Environment (JRE 1.5 or later from java.sun.com ) http://www.newlisp.org/index.cgi?page=IDE
but the newlisp engine itself does not need java, you can run lisp program fac.txt like:
newlisp fac.txt
i found that the graphics examples in the C:\Program Files\newlisp\guiserver folder also needs java runtime.
so i have made an experiment using my older computer which have no java installed , i have installed newlisp , then running newLISP-GS sortcut, and it does not run, instead it opens the archive guiserver.jar using the default Alzip .
so i have installed java runtime from here:
http://www.java.com/en/download/manual.jsp
downloading the offline version (15 MB), since the online version does does not installed.
now i can run the ide, and the graphics.
indeed i hate java, but they choose it for the ide and graphics for cross platform compatibility.
regards

PS: you may have java installed, but due to different versions clicking the ide shortcut does not work.
so try running it directly from the newlisp folder:
newlisp newlisp-edit.lsp

danbaron
02-11-2010, 19:53
[font=courier new][size=8pt]I have Java (JDK) 1.6 installed.

No matter what I do, like for you, Zak, instead of starting the IDE, it opens the archive, guiserver.jar.

I also tried from the newlisp folder, and it does the same thing.

Dan

danbaron
03-11-2010, 06:22
[font=courier new][size=8pt]When I execute, "newlisp newlisp-edit.lsp", the archive is opened.

When I execute, "java -jar guiserver.jar", a console window opens.

In the console window it says,

"newLISP-GS v.1.36 on Windows Vista" (this is wrong, I have Windows 7)

"double buffering supported"

"listening on 64001"

zak
03-11-2010, 07:14
this is one of the bad things with java, it is easily broken with successive upgrades, if you want to continue ; uninstall java whether the jdk or jre, then delete manually everything in C:\Program Files\Java\ then reinstall the newest runtime from the offline file here http://www.java.com/en/download/manual.jsp
may be it will work.
and regarding vista or windows 7, many programs are regarding windows 7 as vista such as system commander which i am using to boot between different os's, it is displaying win7 as vista, it is said that windows 7 is an optimised vista, and not a real new os.