Embedding LUA in a .so

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Embedding LUA in a .so

Maxime Petazzoni
Hi,

Is there a simple and esthetic way to embed Lua source code into a C
source file ? My problem is that I'd like to bundle in a .so that
cannot open another file (with luaL_openfile) for example.

My first thought is to put the Lua chunk into a big ugly #define line,
such as :

  #define LUA_CODE "print('hello, world')"

And then use loadbuffer and run the compiled chunk, but it's a bit
hard to escape the Lua chunk code from a separate file so it can be
safely included in the #define line.

Any hints or previous experience ?

Bests,
- Maxime

-- 
Maxime Petazzoni (http://www.bulix.org)
 -- gone crazy, back soon. leave message.

Attachment: signature.asc
Description: Digital signature

Reply | Threaded
Open this post in threaded view
|

Re: Embedding LUA in a .so

Luiz Henrique de Figueiredo
> Is there a simple and esthetic way to embed Lua source code into a C
> source file ? My problem is that I'd like to bundle in a .so that
> cannot open another file (with luaL_openfile) for example.

I'm not sure what you mean, but have a look at srlua:
	http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/#srlua
	

Reply | Threaded
Open this post in threaded view
|

Re: Embedding LUA in a .so

Maxime Petazzoni
* Luiz Henrique de Figueiredo <[hidden email]> [2006-03-10 12:23:11]:

> > Is there a simple and esthetic way to embed Lua source code into a C
> > source file ? My problem is that I'd like to bundle in a .so that
> > cannot open another file (with luaL_openfile) for example.
> 
> I'm not sure what you mean, but have a look at srlua:
> 	http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/#srlua

Not exactly. I need to produce a .so that will further be loaded by
another program, but I can only give this program one single .so file,
so the .so must include in some way the Lua code to be executed.

The goal is to be able to use Lua programming (simpler) in an existing
"loading" architecture originally made for loading C code -shared
compiled.

- Maxime


-- 
Maxime Petazzoni (http://www.bulix.org)
 -- gone crazy, back soon. leave message.

Attachment: signature.asc
Description: Digital signature

Reply | Threaded
Open this post in threaded view
|

Re: Embedding LUA in a .so

Antonio Scuri
In reply to this post by Maxime Petazzoni
At 12:18 10/3/2006, Maxime Petazzoni wrote:
Any hints or previous experience ?

  We use luac and bin2c to do that.

luac creates a LO from LUA
bin2c creates a LOH from LUA

  Inside the code we simply do #include the LOH.

Best,
scuri


Reply | Threaded
Open this post in threaded view
|

Re: Embedding LUA in a .so

Maxime Petazzoni
* Antonio Scuri <[hidden email]> [2006-03-10 12:45:01]:

> At 12:18 10/3/2006, Maxime Petazzoni wrote:
> >Any hints or previous experience ?
> 
>   We use luac and bin2c to do that.
> 
> luac creates a LO from LUA
> bin2c creates a LOH from LUA
> 
>   Inside the code we simply do #include the LOH.

bin2c is just perfect. Thanks!

- Maxime

-- 
Maxime Petazzoni (http://www.bulix.org)
 -- gone crazy, back soon. leave message.

Attachment: signature.asc
Description: Digital signature