Advice Mixing PHP and Lua?

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

Advice Mixing PHP and Lua?

Patrick Mc(avery
Hi Everyone

I am new to Lua and still reading Roberto's book. I am absolutely loving
everything that I have learned so far. It's amazing how many things are
the way I was hoping they would be in the other languages that I learned
but were not.

I am going to use Lua with C++ and it looks like a perfect match already
but I also want to do some web based stuff. PHP just has such a large
set of libraries of which one I have already become Dependant on. Lua
seems like a better language but PHP has such a head start with the web.
What would be the best way to mesh PHP code and Lua? I know there is a
PECL extension for embedding the Lua interpretor, has anyone else used
this?Is there a better way?

Thanks in advance-Patrick

Reply | Threaded
Open this post in threaded view
|

Re: Advice Mixing PHP and Lua?

Marcelo Araujo
lua PECL extension needs several improvements. Depending on what you are going to do, it may not fit.

On Tue, Oct 27, 2009 at 2:36 PM, Patrick <[hidden email]> wrote:
Hi Everyone

I am new to Lua and still reading Roberto's book. I am absolutely loving
everything that I have learned so far. It's amazing how many things are
the way I was hoping they would be in the other languages that I learned
but were not.

I am going to use Lua with C++ and it looks like a perfect match already
but I also want to do some web based stuff. PHP just has such a large
set of libraries of which one I have already become Dependant on. Lua
seems like a better language but PHP has such a head start with the web.
What would be the best way to mesh PHP code and Lua? I know there is a
PECL extension for embedding the Lua interpretor, has anyone else used
this?Is there a better way?

Thanks in advance-Patrick




--
Marcelo Araujo


Reply | Threaded
Open this post in threaded view
|

Re: Advice Mixing PHP and Lua?

Fernando Paredes García
In reply to this post by Patrick Mc(avery
Lua is the first ever language I've learned because I really wanted it, not because of study or work. So I understand what you say :)

I have started a project for those who want to migrate from PHP to Lua, it is called Nutria:
http://gitorious.org/nutria
http://gitorious.org/nutria/pages/Home

Blessings!

On Tue, Oct 27, 2009 at 11:36 AM, Patrick <[hidden email]> wrote:
Hi Everyone

I am new to Lua and still reading Roberto's book. I am absolutely loving
everything that I have learned so far. It's amazing how many things are
the way I was hoping they would be in the other languages that I learned
but were not.

I am going to use Lua with C++ and it looks like a perfect match already
but I also want to do some web based stuff. PHP just has such a large
set of libraries of which one I have already become Dependant on. Lua
seems like a better language but PHP has such a head start with the web.
What would be the best way to mesh PHP code and Lua? I know there is a
PECL extension for embedding the Lua interpretor, has anyone else used
this?Is there a better way?

Thanks in advance-Patrick




--
Fernando P. García, http://www.develcuy.com
Developer - Analista de Sistemas
+51 1 9 8991 7871, Calle Santa Catalina Ancha #377, Cusco -Perú

** Antes de imprimir este mensaje piensa en tu compromiso con el medio ambiente, protegerlo depende de tí.
Reply | Threaded
Open this post in threaded view
|

Re: Advice Mixing PHP and Lua?

Bertrand Mansion
In reply to this post by Patrick Mc(avery
On Tue, Oct 27, 2009 at 5:36 PM, Patrick
<[hidden email]> wrote:

> Hi Everyone
>
> I am new to Lua and still reading Roberto's book. I am absolutely loving
> everything that I have learned so far. It's amazing how many things are
> the way I was hoping they would be in the other languages that I learned
> but were not.
>
> I am going to use Lua with C++ and it looks like a perfect match already
> but I also want to do some web based stuff. PHP just has such a large
> set of libraries of which one I have already become Dependant on. Lua
> seems like a better language but PHP has such a head start with the web.
> What would be the best way to mesh PHP code and Lua? I know there is a
> PECL extension for embedding the Lua interpretor, has anyone else used
> this?Is there a better way?
>
> Thanks in advance-Patrick

Hi Patrick,

If you want to go PHP+Lua, the best is to use the PECL extension. You
can try my branch here, I have fixed a few little things:
http://svn.php.net/viewvc/pecl/lua/branches/NO_LUA_TABLE/

I use this in my trylua experiment and it's working great.
http://trylua.mamasam.com

The PECL extension needs more love, if you want to work on it, you are
welcome, just let me know.

--
Bertrand Mansion
Mamasam
Reply | Threaded
Open this post in threaded view
|

Re: Advice Mixing PHP and Lua?

troels knak-nielsen
Which libraries in particular are you using from php?

--
troels

On Tue, Oct 27, 2009 at 8:04 PM, Bertrand Mansion <[hidden email]> wrote:

> On Tue, Oct 27, 2009 at 5:36 PM, Patrick
> <[hidden email]> wrote:
>> Hi Everyone
>>
>> I am new to Lua and still reading Roberto's book. I am absolutely loving
>> everything that I have learned so far. It's amazing how many things are
>> the way I was hoping they would be in the other languages that I learned
>> but were not.
>>
>> I am going to use Lua with C++ and it looks like a perfect match already
>> but I also want to do some web based stuff. PHP just has such a large
>> set of libraries of which one I have already become Dependant on. Lua
>> seems like a better language but PHP has such a head start with the web.
>> What would be the best way to mesh PHP code and Lua? I know there is a
>> PECL extension for embedding the Lua interpretor, has anyone else used
>> this?Is there a better way?
>>
>> Thanks in advance-Patrick
>
> Hi Patrick,
>
> If you want to go PHP+Lua, the best is to use the PECL extension. You
> can try my branch here, I have fixed a few little things:
> http://svn.php.net/viewvc/pecl/lua/branches/NO_LUA_TABLE/
>
> I use this in my trylua experiment and it's working great.
> http://trylua.mamasam.com
>
> The PECL extension needs more love, if you want to work on it, you are
> welcome, just let me know.
>
> --
> Bertrand Mansion
> Mamasam
>
Reply | Threaded
Open this post in threaded view
|

Re: Advice Mixing PHP and Lua?

Patrick Mc(avery
Hi Troels

Actually the only thing I am really suck with is FPDF. I want to
generate PDF quotes for my small business.

Thanks-Patrick


troels knak-nielsen wrote:
> Which libraries in particular are you using from php?
>
>  

Reply | Threaded
Open this post in threaded view
|

Re: Advice Mixing PHP and Lua?

Petite Abeille-2-2

On Oct 27, 2009, at 8:34 PM, Patrick wrote:

> Actually the only thing I am really suck with is FPDF. I want to
> generate PDF quotes for my small business.

Perhaps something like lpdf would help?

http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/#lpdf

lpdf is a binding for PDFlib:

http://www.pdflib.com/

Reply | Threaded
Open this post in threaded view
|

Re: Advice Mixing PHP and Lua?

Luiz Henrique de Figueiredo
> On Oct 27, 2009, at 8:34 PM, Patrick wrote:
>
> > Actually the only thing I am really suck with is FPDF. I want to
> > generate PDF quotes for my small business.
>
> Perhaps something like lpdf would help?
>
> http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/#lpdf
>
> lpdf is a binding for PDFlib:

FPDF explicitly avoids PDFlib.

Looking at the code in FPDF, it seems to be easy to convert to pure Lua,
but of course I know no PHP. If anyone knows PHP and can confirm that it'd
be easy to convert to pure Lua, I could try it.
Reply | Threaded
Open this post in threaded view
|

Re: Advice Mixing PHP and Lua?

Luiz Henrique de Figueiredo
> FPDF explicitly avoids PDFlib.

Another route would be a Lua binding to the free libHaru:
        http://luahpdf.luaforge.net/
Reply | Threaded
Open this post in threaded view
|

Re: Advice Mixing PHP and Lua?

troels knak-nielsen
In reply to this post by Patrick Mc(avery
On Tue, Oct 27, 2009 at 8:34 PM, Patrick
<[hidden email]> wrote:
> Hi Troels
>
> Actually the only thing I am really suck with is FPDF. I want to
> generate PDF quotes for my small business.
>

If you generate pdf's, chances are that you are doing it in an offline
mail-merge fashion (just guessing here of course, but that's a common
thing to do). In that case, you could keep your current php code for
generating pdf's, but use Lua for everything else. There is no rule
that you *must* use the same language for every part of your
application.
Reply | Threaded
Open this post in threaded view
|

Re: Advice Mixing PHP and Lua?

Stefan-8
In reply to this post by Luiz Henrique de Figueiredo
Luiz Henrique de Figueiredo wrote:

>> On Oct 27, 2009, at 8:34 PM, Patrick wrote:
>>
>>> Actually the only thing I am really suck with is FPDF. I want to
>>> generate PDF quotes for my small business.
>> Perhaps something like lpdf would help?
>>
>> http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/#lpdf
>>
>> lpdf is a binding for PDFlib:
>
> FPDF explicitly avoids PDFlib.

Perhaps LuaHPDF then?

http://luahpdf.luaforge.net/

>
> Looking at the code in FPDF, it seems to be easy to convert to pure Lua,
> but of course I know no PHP. If anyone knows PHP and can confirm that it'd
> be easy to convert to pure Lua, I could try it.
>

The PDF dialect that FPDF creates appears to be a slightly older one,
which is basically a red-headed stepchild of Postscript. This means that
it is just a fancy text template/generation engine. It shouldn't be TOO
hard to port it over... (famous last words)

Reply | Threaded
Open this post in threaded view
|

Re: Advice Mixing PHP and Lua?

Javier Guerra Giraldez
On Tue, Oct 27, 2009 at 3:17 PM, Stefan <[hidden email]> wrote:

>>
>> Looking at the code in FPDF, it seems to be easy to convert to pure Lua,
>> but of course I know no PHP. If anyone knows PHP and can confirm that it'd
>> be easy to convert to pure Lua, I could try it.
>>
>
> The PDF dialect that FPDF creates appears to be a slightly older one, which
> is basically a red-headed stepchild of Postscript. This means that it is
> just a fancy text template/generation engine. It shouldn't be TOO hard to
> port it over... (famous last words)

i can confirm that FPDF does very little more than just outputting
some text to a file.  this is as "PDF" as any other, it's just not
binary-encoded.  i think the only non-obvious thing to do is to
remember the file offsets where each page begins, so that at
file-closing time you can add the 'directory' part.

the second enhancement is not to repeat an embedded image, but to
create a 'resource' and use its definition on each usage.

(disclaimer, this is from hazy memory of reading several iterations of
the adobe specs, and the source of FPDF and Redland libs)

--
Javier
Reply | Threaded
Open this post in threaded view
|

Re: Advice Mixing PHP and Lua?

troels knak-nielsen
In reply to this post by Stefan-8
On Tue, Oct 27, 2009 at 9:17 PM, Stefan <[hidden email]> wrote:
>> Looking at the code in FPDF, it seems to be easy to convert to pure Lua,
>> but of course I know no PHP. If anyone knows PHP and can confirm that it'd
>> be easy to convert to pure Lua, I could try it.
>>
>
> The PDF dialect that FPDF creates appears to be a slightly older one, which
> is basically a red-headed stepchild of Postscript. This means that it is
> just a fancy text template/generation engine. It shouldn't be TOO hard to
> port it over... (famous last words)

I just skimmed the code through. It's very procedural in style, which
probably makes it relatively simple to understand and port, even if
it's ugly as heck. The library depends on the zlib extension for
compression, and on gdlib for converting gif images into png, and for
finding the dimensions of image files. You'll need replacements for
both of those. Otherwise it looks like something that could be done in
a weekend.

If you give it a try, you're welcome to ask me for help. I know php pretty well.

--
troels
Reply | Threaded
Open this post in threaded view
|

Re: Advice Mixing PHP and Lua?

Patrick Mc(avery
In reply to this post by Stefan-8
Wow, you guys are awesome thanks so much for these great responses.

My Lua skills are still minimal but if a port of FPDF does need to be
done, I would like to contribute in some way.

I just read today that Apache will come with Mod_Lua by default. This
sounds like very exciting news. I am just wondering, if it came down to
a FPDF port vs LuaHPDF, which would be better to bring new users to Lua?
If Mod_Lua will come pre-installed does this mean that many economy
hosting providers will eventually have Lua by default as well?

LuaHDPF must be complied but an FPDF port would be just another Lua
script. Would this make it easier to attract new users?
Reply | Threaded
Open this post in threaded view
|

Re: Advice Mixing PHP and Lua?

Javier Guerra Giraldez
On Tue, Oct 27, 2009 at 3:46 PM, Patrick
<[hidden email]> wrote:
> Wow, you guys are awesome thanks so much for these great responses.
>
> My Lua skills are still minimal but if a port of FPDF does need to be
> done, I would like to contribute in some way.

a big help would be to detail all the PDF objects created by FPDF,
together with a template to reproduce them.  using that as a base
would be a lot faster than using the adobe docs.


> I just read today that Apache will come with Mod_Lua by default. This
> sounds like very exciting news. I am just wondering, if it came down to
> a FPDF port vs LuaHPDF, which would be better to bring new users to Lua?
> If Mod_Lua will come pre-installed does this mean that many economy
> hosting providers will eventually have Lua by default as well?

as the Django people are learning, having the language interpreter
embedded in the apache processes usually isn't the best idea.
currently the advised deployment architecture uses mod_wsgi instead of
mod_python, especially using the 'daemon' mode, which spawns the
python VM(s) separate from apache's own processes/threads.  Not too
different from FastCGI, but with better task longevity management.

check this: http://www.modpython.org/pipermail/mod_python/2007-July/024080.html

> LuaHDPF must be complied but an FPDF port would be just another Lua
> script. Would this make it easier to attract new users?

totally.  the 'pure Lua' tag is a big plus in any project

--
Javier
Reply | Threaded
Open this post in threaded view
|

Re: Advice Mixing PHP and Lua?

Bertrand Mansion
In reply to this post by Luiz Henrique de Figueiredo
On Tue, Oct 27, 2009 at 9:02 PM, Luiz Henrique de Figueiredo
<[hidden email]> wrote:

>> On Oct 27, 2009, at 8:34 PM, Patrick wrote:
>>
>> > Actually the only thing I am really suck with is FPDF. I want to
>> > generate PDF quotes for my small business.
>>
>> Perhaps something like lpdf would help?
>>
>> http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/#lpdf
>>
>> lpdf is a binding for PDFlib:
>
> FPDF explicitly avoids PDFlib.
>
> Looking at the code in FPDF, it seems to be easy to convert to pure Lua,
> but of course I know no PHP. If anyone knows PHP and can confirm that it'd
> be easy to convert to pure Lua, I could try it.
>

Hi Luiz,

FPDF is very popular in the PHP world because it is free and easy to
use. Its pseudo OO code is ugly though.
But TCPDF, which is even more useful is even uglier, probably the
ugliest code I have seen in PHP ever. But it does the job quite well
and has lots of features. I produce this kind of documents with it :
http://www.intermedes.com/voyage/2010/174-chili-du-cap-horn-atacama.pdf

The best PHP PDF class in terms of "code beauty" is Zend_PDF.
Unfortunately it is incomplete as for example it doesn't support
cells. But its API is nice and powerful. You might want to have a look
at it before you start working on a pure Lua PDF module.

If you are more familiar with Python, there are at least two FPDF
ports in Python:
http://juanfernandoe.googlepages.com/
http://www.sistemasagiles.com.ar/trac/browser/pyfpdf/FPDF.py

There are also some Ruby ports:
http://code.zhdk.ch/projects/leihs/browser/trunk/lib/fpdf/fpdf.rb
http://github.com/edwinmoss/rfpdf

It would be nice to have such a thing in Lua, indeed :)

--
Bertrand Mansion
Mamasam
Reply | Threaded
Open this post in threaded view
|

Re: Advice Mixing PHP and Lua?

David Given
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bertrand Mansion wrote:
[...]
> FPDF is very popular in the PHP world because it is free and easy to
> use. Its pseudo OO code is ugly though.
> But TCPDF, which is even more useful is even uglier, probably the
> ugliest code I have seen in PHP ever.

On the gripping hand, don't forget that you can also write out an XSL-FO
file, which is dead easy because it's just simple XML, then run the
result through fop and generate PDF from that.

This has the advantage in that you can trivially define all your style
in off-line XSLT documents so that all your Lua code needs to concern
itself with is the actual content... but it has the disadvantage in that
 all your style is stored in off-line XSLT documents.

http://www.learn-xsl-fo-tutorial.com/
http://xmlgraphics.apache.org/fop/

- --
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "There is nothing in the world so dangerous --- and I mean *nothing*
│ --- as a children's story that happens to be true." --- Master Li Kao,
│ _The Bridge of Birds_
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFK52v3f9E0noFvlzgRAlkCAJ0Zll2s9KRLpxijDQYb1MrXWszq0wCfZ7U4
c56DR1CXD2Cn+wPPYSTW9hs=
=9tKG
-----END PGP SIGNATURE-----
Reply | Threaded
Open this post in threaded view
|

Re: Advice Mixing PHP and Lua?

Patrick Mc(avery
In reply to this post by Javier Guerra Giraldez
Would it be okay if I renamed this thread "pure Lua PDF module"?

My original post regarding PHP has been narrowed down to this topic and it might be easier for others to follow later.


> a big help would be to detail all the PDF objects created by FPDF,
> together with a template to reproduce them.  using that as a base
> would be a lot faster than using the adobe docs.
>  
I am at an intermediate level with Python and PHP(I repair Spectrometers
for a living, I am not a pro programmer). I could probably at least go
through these code examples that Bertrand has given plus FPDF and
document what each part does. Then maybe someone could help turn it into
proper Lua code.

I am still overloaded with my Son(who's Autism is getting much better)
and my Daughter will be here in a few weeks but if you can bare with my
slow pace I will give it my best.

The FPDF forum is also a friendly place, I might be able to get some
help here.

Patrick



Reply | Threaded
Open this post in threaded view
|

Re: Advice Mixing PHP and Lua?

Fernando Paredes García
Patrick, If you do the migration from PHP to Lua, count with me!!! I'm using Nutria to migrate a PHP project with about 1.5MB of code... I have saved a lot of time and learned Lua at the same time, I can bring you support porting the missing PHP functions in Nutria and a quick start with PHP to Lua.

Blessings!

On Tue, Oct 27, 2009 at 5:31 PM, Patrick <[hidden email]> wrote:
Would it be okay if I renamed this thread "pure Lua PDF module"?

My original post regarding PHP has been narrowed down to this topic and it might be easier for others to follow later.


> a big help would be to detail all the PDF objects created by FPDF,
> together with a template to reproduce them.  using that as a base
> would be a lot faster than using the adobe docs.
>
I am at an intermediate level with Python and PHP(I repair Spectrometers
for a living, I am not a pro programmer). I could probably at least go
through these code examples that Bertrand has given plus FPDF and
document what each part does. Then maybe someone could help turn it into
proper Lua code.

I am still overloaded with my Son(who's Autism is getting much better)
and my Daughter will be here in a few weeks but if you can bare with my
slow pace I will give it my best.

The FPDF forum is also a friendly place, I might be able to get some
help here.

Patrick






--
Fernando P. García, http://www.develcuy.com
Developer - Analista de Sistemas
+51 1 9 8991 7871, Calle Santa Catalina Ancha #377, Cusco -Perú

** Antes de imprimir este mensaje piensa en tu compromiso con el medio ambiente, protegerlo depende de tí.
Reply | Threaded
Open this post in threaded view
|

Re: Advice Mixing PHP and Lua?

Philippe Lhoste
In reply to this post by Bertrand Mansion
On 27/10/2009 22:12, Bertrand Mansion wrote:
> FPDF is very popular in the PHP world because it is free and easy to
> use. Its pseudo OO code is ugly though.
> But TCPDF, which is even more useful

Indeed, I was about to point to it: FPDF has an annoying limitation for non-English
speaking people: AFAIK, it doesn't support Unicode.
Hence the usage of TCPDF <http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf>
or UFPDF <http://acko.net/node/56>

If some effort must be put in a port, I think it might be better to start from a more
universal code base. Or to inject proper Unicode support in the port effort.

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --