newlisp -x and embedding data files

Q&A's, tips, howto's

newlisp -x and embedding data files

Postby protozen » Fri Jun 27, 2014 4:25 am

Is there a way to embedded files into the compiled executable? I would like to build a self contained website distributed as an executable - delivering static files that have been embedded. Alternatively, can the executable be rewritten if updates were made through such a web app?
protozen
 
Posts: 36
Joined: Thu Aug 22, 2013 4:02 am

Re: newlisp -x and embedding data files

Postby HPW » Fri Jun 27, 2014 8:10 am

Hello,

You may have a look at the link option:

http://www.newlisp.org/downloads/newlis ... .html#link

Regards
Hans-Peter
HPW
 
Posts: 1375
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany

Re: newlisp -x and embedding data files

Postby ryuo » Fri Jun 27, 2014 6:59 pm

If all else fails you can embed the files into the source code as symbols via [text][/text] blocks. You could put these in external modules. newLISP may embed all the modules loaded via the load function, but I am not heavily familiar with how this feature works. As a last resort, you could create a script that builds the full source file from the individual modules before newLISP creates an executable from it. This is easily done with a Makefile, if you've ever used UNIX development tools.
ryuo
 
Posts: 43
Joined: Wed May 21, 2014 4:40 pm

Re: newlisp -x and embedding data files

Postby protozen » Fri Jun 27, 2014 9:34 pm

Thanks for the input ryuo, this is what I was thinking I'd have to do if there was no sanctioned way.
protozen
 
Posts: 36
Joined: Thu Aug 22, 2013 4:02 am

Re: newlisp -x and embedding data files

Postby ralph.ronnquist » Sat Jun 28, 2014 1:08 am

I don't think newlisp -x embeds other than the nominated module.
However, you may well use
Code: Select all
(write-file "myembedding.lsp" (source))

which gets you a quite decent snapshot of the currently loaded state, in newlisp source.
Then just add the "run clauses", and embed that.
ralph.ronnquist
 
Posts: 209
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: newlisp -x and embedding data files

Postby ralph.ronnquist » Sat Jun 28, 2014 3:17 am

Hmm; I'm sure you'd work it out, but as I tried it, I realized it requires a slightly more complex source clause, such as:
Code: Select all
(write-file "myembedding.lsp"
  (join (map source (filter (fn (s) (context? (eval s))) (symbols)))
    ""))

and this needs to be in the MAIN context.
ralph.ronnquist
 
Posts: 209
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: newlisp -x and embedding data files

Postby ralph.ronnquist » Sat Jun 28, 2014 10:24 am

I already had this on my todo list since I also much prefer free standing executables for production code. So, just to complete the thought, I put together a small embedding module, which takes care of including loaded files into the embedding by means of replacing the standard load function. I've made it available here,
http://www.realthing.com.au/files/newlisp/embed.lsp
It kept me entertained a cold and windy winter Saturday afternoon.
ralph.ronnquist
 
Posts: 209
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: newlisp -x and embedding data files

Postby protozen » Wed Jul 09, 2014 3:31 am

ralph.ronnquist wrote:I already had this on my todo list since I also much prefer free standing executables for production code. So, just to complete the thought, I put together a small embedding module, which takes care of including loaded files into the embedding by means of replacing the standard load function. I've made it available here,
http://www.realthing.com.au/files/newlisp/embed.lsp
It kept me entertained a cold and windy winter Saturday afternoon.

Hey thanks for this, I appreciate your input and work.
protozen
 
Posts: 36
Joined: Thu Aug 22, 2013 4:02 am

Re: newlisp -x and embedding data files

Postby Lutz » Wed Jul 09, 2014 4:19 am

Also linked from here: http://www.newlisp.org/modules/various/index.html

Ps: changed the location link
Lutz
 
Posts: 5279
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Re: newlisp -x and embedding data files

Postby ralph.ronnquist » Wed Jul 16, 2014 11:31 am

I thought to add the note, that often it's best to skip the final embedding step, since that step must be done with the newlisp runtime environment of the target machine. E.g., I have a development machine with libffi.so.6 and a target machine with only libffi.so.5, so my embedded program doesn't run happily ever after.

The point is that the embedded program is still dynamically linked. Therefore it's probably better to rather export the embedding base, which is a self-contained newlisp source, and run this with the target newlisp runtime. Obviously you should still have the same newlisp version.

Thus, my step 3 should be to add a inital line of
Code: Select all
#!/usr/bin/newlisp

(or similar) to the embedding base, to make it an executable script, instead of the -x embedding to make it a dynamic ELF.

Though, maybe one can pre-link a dynamic executable into an exportable static executable (for compatible OS), but I'm not familar with the hoops and incantations for this.
ralph.ronnquist
 
Posts: 209
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia


Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 2 guests