Page 1 of 2
COM in newLISP
Posted: Sat Nov 10, 2007 9:50 am
by codernwo
Hi,
I have just discovered newLISP and it happens to be my first Lisp. I find it powerful enough to think of adopting it for my scripting needs.
However iam disappointed that there is no COM support . Since most of my scripting on windows involves automation, i find this a serious handicap.
Has anyone thought of adapting a library like disphelper for newlisp? I have seen lb_dishelper(for liberty basic) and comlib(for REBOL) which use a dll version of the disphelper library.
I think this can be done for newlisp also. However my lisp is still at the learning stage to do this.
Any thoughts on this anyone?
codernwo
Posted: Sat Nov 10, 2007 4:48 pm
by Lutz
There shouldn't be a problem to import the relevant DLLs.
newLISP's library interface needs good C-language knowledge to use it, but is also a very tight and fast interface. If you are familiar with C you might want to look at chapter 20 in the "Code Patterns in newLISP" document:
http://newlisp.org/CodePatterns.html#extending
This file is also linked from here:
http://newlisp.org/index.cgi?Documentation
In any case, welcome to newLISP
Lutz
Posted: Sun Nov 11, 2007 4:45 am
by codernwo
Thanks for the tip. I intend to start work on this soon.I Will post any development made.
codernwo
Posted: Mon Nov 12, 2007 6:36 pm
by m35
You may be interested in the COM work over at the Autohotkey scripting language:
http://www.autohotkey.com/forum/topic22923.html
http://www.autohotkey.com/forum/topic21674.html
I spent a month or so working on COM inclusion in newLISP, but eventually dropped it for the better "
Easycom.dll" program, which was then dropped to develop the "
ws4ahk" library. :)
The easiest way to do COM is to use Microsoft Scripting Control (like ws4ahk uses). The next easiest would probably be to make a DLL to do most of the work (like Easycom.dll does). Finally you could just do all the raw COM calls entirely in newLISP (my first efforts).
You're welcome to have the leftover newLISP or Easycom.dll code if you're interested.
Posted: Tue Nov 13, 2007 6:08 pm
by SHX
m35
The easiest way to do COM is to use Microsoft Scripting Control (like ws4ahk uses).
I would like to understand what you are saying.
Are you saying that currenlty there is a facility within Newlisp to use Microsoft Scripting Control and then you can access com objects via a scripting language?
Steven
Posted: Tue Nov 13, 2007 8:30 pm
by m35
SHX
newLISP does not currently have access to the Microsoft Scripting Control. However, by creating a newLISP interface to it (such as "ws4ahk" does for Autohotkey), then yes, you can execute VBScript or JScript code directly in your newLISP code. Thus you can gain easy access to COM.
Posted: Tue Nov 13, 2007 9:09 pm
by SHX
However, by creating a newLISP interface to it
m35,
Excuse my ignorance but does that mean that the interface to the Microsoft Scripting Control can be written in Newlisp script by interfacing with the dll or does it mean some sort of external interface in c or something.
Steven
Posted: Tue Nov 13, 2007 9:46 pm
by m35
SHX wrote:Excuse my ignorance but does that mean that the interface to the Microsoft Scripting Control can be written in Newlisp script by interfacing with the dll or does it mean some sort of external interface in c or something.
Sorry, I misunderstood what you were asking.
COM can be directly accessed by any language that can do 2 things:
* Import and call DLL functions
* Call functions at arbitrary memory locations
Since newLISP can do these things, it can have direct access to the Microsoft Scripting Control DLL (msscript.ocx), as well as all the other DLLs necessary to interface with COM. It doesn't need any external C or C++ interface.
Posted: Tue Nov 13, 2007 10:01 pm
by SHX
Thanks, now I see.
It would be great if someone would develop such a wrapper.
Posted: Thu Nov 15, 2007 8:53 am
by codernwo
Some neat tips and links from m35. Thanks.
Regarding the approach, though the C DLL approach is easier for me I would like to build an interface entirely in newLisp. Hence I would like to take up m35's offer of the leftover newLisp code and build on it. This will also help me to learn newLisp in a practical way.
So the next question(to m35) is where do I get this leftover newLisp code? ;-)
Posted: Sun Dec 02, 2007 7:40 pm
by m35
While codernwo gets to mull over my crazy code, I made a quick port of the ws4ahk script to newLISP. It's not as complete, and may even be a little incorrect, but my brief tests seemed to work. Just throwing this out here in case anyone is interested.
http://www.autohotkey.net/~easycom/winscript.lsp
Edit: Updated url for v0.11
Posted: Mon Dec 03, 2007 2:33 pm
by Lutz
Special thanks for documenting this useful module for newLISPdoc.
There is a new special section
http://newlisp.org/modules/ where all commented modules and other source files can be collected.
I started with m35's winscript module and and a link to Dmitry's utilities. If I forgot anything which was published earlier and needs to be included, republish the file here on the board and I can copy it from there.
Lutz
ps: I will upload the updated newlispdoc utility with improved page headers and expanded functionality for index paged later.
...responding to the last message
Posted: Mon Dec 03, 2007 7:01 pm
by cormullion
Hey Lutz - ! Great to see the modules clustering together... But browsing through the documentation for these modules, some of them say:
To use this module include the following load statement at the beginning of the program file:
(load "/usr/share/newlisp/crypto.lsp")
But on my system everything is in "/usr/share/newlisp/modules/:"
Code: Select all
newlisp:
guiserver:
allfonts-demo.lsp
animation-demo.lsp
border-layout-demo.lsp
button-demo.lsp
clipboard-demo.lsp
cursor-demo.lsp
drag-demo.lsp
font-demo.lsp
frameless-demo.lsp
html-demo.lsp
image-demo.lsp
mouse-demo.lsp
move-resize-demo.lsp
pinballs-demo.lsp
properties-demo.lsp
rotation-demo.lsp
shapes-demo.lsp
sound-demo.lsp
stroke-demo.lsp
tabs-demo.lsp
textrot-demo.lsp
uppercase.lsp
widgets-demo.lsp
word-count.lsp
guiserver.jar
guiserver.lsp
init.lsp
modules:
cgi.lsp
crypto.lsp
ftp.lsp
gmp.lsp
infix.lsp
mysql.lsp
mysql5.lsp
odbc.lsp
pop3.lsp
postscript.lsp
smtp.lsp
sqlite3.lsp
stat.lsp
unix.lsp
xmlrpc-client.lsp
zlib.lsp
util:
httpd-conf.lsp
link.lsp
newlisp.vim
syntax.cgi
(Sorry for the non-Windows post...)
Posted: Mon Dec 03, 2007 7:22 pm
by newdep
Nice module, great work!!
Posted: Mon Dec 03, 2007 10:42 pm
by m35
Thanks newdep.
I found a memory leak, so I'll upload a new version later.
But I wanted to ask if anyone can think of a better way to do these get-short and get-single (i.e. float) functions. These seem sloppy, but nothing is coming to me.
Code: Select all
(define (get-short int-address , s)
(setq s " ")
(cpymem int-address (address s) 2)
(first (unpack "d" s))
)
(define (get-single int-address , s)
(setq s " ")
(cpymem int-address (address s) 4)
(first (unpack "f" s))
)
Posted: Tue Dec 04, 2007 1:53 am
by Lutz
Can you explain in words what you are trying to do? Or explain in terms of 'C' language? It should not be necessary to copy to another address before unpacking:
Code: Select all
> (set 'x 0x01020304)
16909060
> (unpack "c" (+ 0 (address x)))
(4)
> (unpack "c" (+ 1 (address x)))
(3)
> (unpack "c" (+ 2 (address x)))
(2)
> (unpack "c" (+ 3 (address x)))
(1)
>
or
Code: Select all
> (unpack "c" "\001\002\003\004")
(1)
> (unpack "d" "\001\002\003\004")
(513)
> (unpack "ld" "\001\002\003\004")
(67305985)
Perhaps this can help:
http://newlisp.org/CodePatterns.html#extending
Lutz
ps: all examples on little endian CPU architecture
Posted: Tue Dec 04, 2007 2:50 am
by m35
Sorry, I guess I should have explained what I was trying to do.
For
get-short, I'm trying to duplicate the behavior of get-int, but I just want 16-bits instead of 32-bits.
For
get-single, I'm trying to duplicate the behavior of get-float, but I want a 32-bit floating point number instead of a 64-bit one.
...
And now I read the manual a little closer and it says
(unpack str-format str-addr-packed)
Note that str-addr-packed may also be an integer representing a memory address.
So I guess this should do that I need.
Code: Select all
(define (get-short int-address)
(first (unpack "d" int-address))
)
(define (get-single int-address)
(first (unpack "f" int-address))
)
Heh, silly me ^^;;
Posted: Tue Dec 04, 2007 5:47 am
by m35
New version fixes memory leak and has the better get-short and get-single functions.
http://www.autohotkey.net/~easycom/winscript.lsp
Posted: Tue Dec 04, 2007 1:07 pm
by Lutz
Thanks Mike, I updated it on
http://newlisp.org/modules and also have put a location header pointing to the original. If this is not Ok, let me know.
Lutz
Posted: Thu Dec 06, 2007 2:42 am
by m35
Lutz wrote:put a location header pointing to the original.
No problem Lutz.
I made yet another update to fix another bug.
v0.12
http://www.autohotkey.net/~easycom/winscript.lsp
Posted: Thu Dec 20, 2007 6:16 pm
by m35
In case anyone is actually using the winscript module, a quick warning about the current version (v0.12):
Looking again at winscript.lsp, I see there are a number of memory leaks. These occur in places where a (throw) skips the code to finish the memory handling. The script needs to be corrected with code that would essentially be found in a "finally" block -- releasing temporary memory, and memory that was going to be returned before the error occurred. Of course since there is no finally block, I need to do a partial re-design of the code.
If you're using the module, let me know. It will spur me on to fix this sooner.
Posted: Thu Dec 20, 2007 6:43 pm
by pjot
Well I am not using it yet, but I find this idea really useful! In the past I did a lot of things with VBscript, it is cool that it can be embedded in newLisp now.
Peter
Posted: Mon Dec 24, 2007 3:46 pm
by SHX
I too have plans aon using this important module.
Steven
Posted: Fri Jan 11, 2008 9:40 pm
by m35
winscript v0.20
Memory leaks fixed, and errors better handled. No change to the interface, except added (WINSCRIPT:LastResult) function to get verbose details on errors and internal win32api function results.
winscript.lsp
I can't say I'm super happy with how the new code design turned out, but it works (I hope). I would like to use a more elegant approach, but nothing has come to me.
Posted: Thu Jan 24, 2008 4:01 pm
by m35
winscript v0.21
-Added some missing cleanup if failure during initialization.
winscript.lsp