lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Sep 30, 2009, at 2:27 AM, Mark Hamburg wrote:

That requires storing the code for the chunk in a separate file which is fine for complex processes but is a pain for lightweight processes.

It doesn't necessarily have to be a file, a table of code snippets would do just fine. The crux of it being not to mix code and strings which happen to represent code. No need to change the entire language for that. A bit of organization would usually suffice.

For example, instead of writing 'foreign' code directly inline as a string, one could simply refer to it, e.g:

aDB( ' select name,extract from hit order by name limit %s', ... )


aDB( DML[ 'SelectHit' ], ... )

Alternatively, in the specific case of luaproc, what about using an a serialized function?

Assuming that luaproc.newproc is implemented in terms of loadstring, one could string.dump a function and pass it to luaproc.newproc, e.g.:

luaproc.newproc( string.dump( function() msg = luaproc.receive( "achannel" ) print( msg ) end ) )