newLISP Fan Club

Forum => newLISP and the O.S. => Topic started by: codernwo on November 10, 2007, 01:50:09 AM

Title: COM in newLISP
Post by: codernwo on November 10, 2007, 01:50:09 AM
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
Title:
Post by: Lutz on November 10, 2007, 08:48:12 AM
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
Title:
Post by: codernwo on November 10, 2007, 08:45:52 PM
Thanks for the tip. I intend to start work on this soon.I Will post any development made.





codernwo
Title:
Post by: m35 on November 12, 2007, 10:36:03 AM
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 (//http)" program, which was then dropped to develop the "ws4ahk (//http)" 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.
Title:
Post by: SHX on November 13, 2007, 10:08:45 AM
m35
QuoteThe 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
Title:
Post by: m35 on November 13, 2007, 12:30:45 PM
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.
Title:
Post by: SHX on November 13, 2007, 01:09:11 PM
QuoteHowever, 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
Title:
Post by: m35 on November 13, 2007, 01:46:30 PM
Quote from: "SHX"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.
Title:
Post by: SHX on November 13, 2007, 02:01:05 PM
Thanks, now I see.



It would be great if someone would develop such a wrapper.
Title:
Post by: codernwo on November 15, 2007, 12:53:41 AM
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?   ;-)
Title:
Post by: m35 on December 02, 2007, 11:40:46 AM
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
Title:
Post by: Lutz on December 03, 2007, 06:33:21 AM
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.
Title: ...responding to the last message
Post by: cormullion on December 03, 2007, 11:01:34 AM
Hey Lutz - ! Great to see the modules clustering together... But browsing through the documentation for these modules, some of them say:


QuoteTo 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/:"


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...)
Title:
Post by: newdep on December 03, 2007, 11:22:41 AM
Nice module, great work!!
Title:
Post by: m35 on December 03, 2007, 02:42:55 PM
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.


(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))
)
Title:
Post by: Lutz on December 03, 2007, 05:53:03 PM
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:


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


> (unpack "c" "01020304")
(1)
> (unpack "d" "01020304")
(513)
> (unpack "ld" "01020304")
(67305985)


Perhaps this can help: http://newlisp.org/CodePatterns.html#extending



Lutz



ps: all examples on little endian CPU architecture
Title:
Post by: m35 on December 03, 2007, 06:50:19 PM
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
Quote(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.
(define (get-short int-address)
    (first (unpack "d" int-address))
)

(define (get-single int-address)
    (first (unpack "f" int-address))
)


Heh, silly me ^^;;
Title:
Post by: m35 on December 03, 2007, 09:47:56 PM
New version fixes memory leak and has the better get-short and get-single functions.



http://www.autohotkey.net/~easycom/winscript.lsp
Title:
Post by: Lutz on December 04, 2007, 05:07:21 AM
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
Title:
Post by: m35 on December 05, 2007, 06:42:16 PM
Quote from: "Lutz"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
Title:
Post by: m35 on December 20, 2007, 10:16:41 AM
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.
Title:
Post by: pjot on December 20, 2007, 10:43:48 AM
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
Title:
Post by: SHX on December 24, 2007, 07:46:35 AM
I too have plans aon using this important module.



Steven
Title:
Post by: m35 on January 11, 2008, 01:40:39 PM
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 (//http)



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.
Title:
Post by: m35 on January 24, 2008, 08:01:52 AM
winscript v0.21



-Added some missing cleanup if failure during initialization.



winscript.lsp (//http)
Title:
Post by: m35 on July 19, 2008, 11:13:26 AM
winscript v0.22



-Minor documentation improvements.

-Added check at initialization if already initialized.

-Fixed error handling when the error doesn't come from the script control.

-Lots of internal cleaning and commenting.



winscript.lsp (//http)