(link'ing and (!'ing Example
Posted: Sat Nov 02, 2002 3:06 am
The following example should provide some clue to
building and (!'ing newLISP executables.
We will use the link.lsp example from the source distribution set to link DoTest-p and SoTest-c into standalone EXEs.
DoTest-p is a parent task that (!s' DoTest-c.exe as a child task.
DoTest-c (loads' DoTest-0.dat which (sets' a return list to pass back to its parent, DoTest-p using an intermediate file DoTest-1.Dat.
Upon return to DoTest-p's control DoTest-1.dat is (loaded.
(link "newlisp.exe" "DoTest-p.exe" "DoTest-p.lsp")
(link "newlisp.exe" "DoTest-c.exe" "DoTest-c.lsp")
;; dolist-0.dat
(set 'done '(X 1 Y 2 Z 3))
;; dotest-p.lsp
(define (run)
(time (if (= (! "DoTest-c.exe") 2) (load "DoTest-1.dat")))
(print return))
(run)
;; eof
;; Dotest-c.lsp
(load "DoTest-0.dat") ; get and set a value for 'done to return.
(set 'fh (open "DoTest-1.dat" "write"))
(write-line (append "(set 'return '" (string done) ")") fh)
(close fh)
(exit 2)
;; eof
;; link.lsp example included in the source distribution set.
;;
(define (link orgExe newExeName lispSourceName)
(set 'size (first (file-info orgExe)))
;; copy newLISP.exe to the newExeName
(copy-file orgExe newExeName)
;; get the binary representation of size
(set 'buff (pack "ld" size))
;; open the new exe for update
(set 'handle (open newExeName "u"))
(search handle "@@@@@@@@")
;; this field gets read by the newLISP startup
(write-buffer handle 'buff 4)
(set 'buff (trim (read-file lispSourceName)))
(set 'keylen (pack "ld" (length buff)))
(write-buffer handle 'keylen 4)
;; append lisp source at the end
(seek handle size)
(set 'buff (encrypt buff (string (length buff))))
(write-buffer handle 'buff (length buff))
(close handle))
;; eof
I have a vague memory of seeing somewhere mention of how to eliminate the flashing black window to nowhere. I can not seem to find it again :(
At one point in my testing I built a feedback loop that flash a window every 300ms till I got it stopped :)
This example and the one that this will evolve into in real life need to pass the file name of the return data to avoid collision with other processes.
Wish List Item:
(get-tmp-filename) returns a unique temp filename using the system call.
building and (!'ing newLISP executables.
We will use the link.lsp example from the source distribution set to link DoTest-p and SoTest-c into standalone EXEs.
DoTest-p is a parent task that (!s' DoTest-c.exe as a child task.
DoTest-c (loads' DoTest-0.dat which (sets' a return list to pass back to its parent, DoTest-p using an intermediate file DoTest-1.Dat.
Upon return to DoTest-p's control DoTest-1.dat is (loaded.
(link "newlisp.exe" "DoTest-p.exe" "DoTest-p.lsp")
(link "newlisp.exe" "DoTest-c.exe" "DoTest-c.lsp")
;; dolist-0.dat
(set 'done '(X 1 Y 2 Z 3))
;; dotest-p.lsp
(define (run)
(time (if (= (! "DoTest-c.exe") 2) (load "DoTest-1.dat")))
(print return))
(run)
;; eof
;; Dotest-c.lsp
(load "DoTest-0.dat") ; get and set a value for 'done to return.
(set 'fh (open "DoTest-1.dat" "write"))
(write-line (append "(set 'return '" (string done) ")") fh)
(close fh)
(exit 2)
;; eof
;; link.lsp example included in the source distribution set.
;;
(define (link orgExe newExeName lispSourceName)
(set 'size (first (file-info orgExe)))
;; copy newLISP.exe to the newExeName
(copy-file orgExe newExeName)
;; get the binary representation of size
(set 'buff (pack "ld" size))
;; open the new exe for update
(set 'handle (open newExeName "u"))
(search handle "@@@@@@@@")
;; this field gets read by the newLISP startup
(write-buffer handle 'buff 4)
(set 'buff (trim (read-file lispSourceName)))
(set 'keylen (pack "ld" (length buff)))
(write-buffer handle 'keylen 4)
;; append lisp source at the end
(seek handle size)
(set 'buff (encrypt buff (string (length buff))))
(write-buffer handle 'buff (length buff))
(close handle))
;; eof
I have a vague memory of seeing somewhere mention of how to eliminate the flashing black window to nowhere. I can not seem to find it again :(
At one point in my testing I built a feedback loop that flash a window every 300ms till I got it stopped :)
This example and the one that this will evolve into in real life need to pass the file name of the return data to avoid collision with other processes.
Wish List Item:
(get-tmp-filename) returns a unique temp filename using the system call.