lua-users home
lua-l archive

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

On Fri, Jun 19, 2009 at 10:19 AM, Eike Decker<> wrote:
> 2009/6/19 V S P <>:
>> Hi,
>> I saw this question on the list once in a while and just
>> wanted to check to see if may be an 'in-process' solution has been
>> developed
>> Currently I invoke lua from PHP by just spawning a process and
>> sending my 'function' arguments as a JSON string into STDIN,
>> lua reads in, processes and sends out another JSON string which
>> I read from PHP on STDOUT pipe.
>> However the above is expensive, and while now I am still in the
>> 'early' stages of the product it is not important,
>> I would like to know if anybody might have developed a simple 'string in
>> / string out'
>> plugin for PHP that could invoke Lua.
> Just a question - if you are falling back to Lua, what do you need PHP
> then for?

Simple : PHP is good at web, Lua is not (well, not enough for my needs
ATM). Lua is good at being embedded, PHP is not.

> In theory you could compile a library for PHP which allows you to
> spawn Lua states in PHP which would minimize the overhead. But then
> again, you could create a Lua module for your webserver which is doing
> the same thing as PHP is doing for the webserver.

I have good news for you, such an extension exists for PHP but has not
yet been released although I am using in production and it's working

What's particularly nice is that PHP has a memory_limit directive, as
well as a max_execution_time directive, Lua doesn't. But Lua has a
debug hook to count the number of times a function has been called,
PHP doesn't.

This means that using both languages you can easily make a Lua sandbox
in PHP. I made one for my Try Lua experiment (I'll put it online as
soon as I find the time).
I am also going to use this method to let my website users create
their own page rendering functions, in Lua. PHP will provide the data
and an API.

Bertrand Mansion