Parsing in C vs. Lua

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

Parsing in C vs. Lua

Jeremy Cowgar
In mod_lua, I parse anything that's shiped to it under the name
of LuaHtml handler. A typical file would be:

<html>
<head>
<title><?lua print(titleOfPage) ?></title>
</head>

<body>
<?lua
for a=1,10 do
  ?>
  Hello, World! (for the <?lua print(a) ?>'n time<br />
  <?lua
end
?>
</body>
</html>

What my parsing code does is converts anything outside of <?lua ... ?>
to something like:

print("<html>")
print("<head>")
print("<title>")
print(titleOfPage)
print("</title>")
...etc...

Without yet doing tests, how would this parsing look if it were done
in Lua instead of C? (Speed wise)?

The parser is already written in C, however, I am going to be creating
some support programs that would be easy to write in Lua, but involve
parsing the HTML into Lua code and I wonder if it's worth, 1. writing
two parsers, or 2. writing my utilities in C and not every writing one
in Lua.

It may just come down to writing a parser and comparing the two, but
if anyone has concrete evidence that Lua will be 10x slower than C, or
something, I may not waste my time.

Thanks,

Jeremy - [hidden email]
http://modlua.cowgar.com

Reply | Threaded
Open this post in threaded view
|

RE: Parsing in C vs. Lua

Andre Carregal
Hi,

CGILua does the parsing entirely in Lua and we've found the solution more
than adequate. If you need more speed, caching or memoizing the resulting
function would be quite simple.

Andre Carregal
http://www.keplerproject.org


> -----Original Message-----
> From: [hidden email]
> [[hidden email] Behalf Of Jeremy Cowgar
> Sent: Tuesday, December 23, 2003 5:12 PM
> To: Lua list
> Subject: Parsing in C vs. Lua
>
>
...
> Without yet doing tests, how would this parsing look if it were done
> in Lua instead of C? (Speed wise)?
>
...
> It may just come down to writing a parser and comparing the two, but
> if anyone has concrete evidence that Lua will be 10x slower than C, or
> something, I may not waste my time.
>
> Thanks,
>
> Jeremy - [hidden email]
> http://modlua.cowgar.com
>



Reply | Threaded
Open this post in threaded view
|

Lua in DLL

Tham
hey ya....merry xmas

i'm writing a toolset that has various components (the app, SDK, plugins
etc).... some of these components (the app and some of the plugins) use lua.
to save space i suggested to myself lua in DLL.

is this possible... will there be any issues??

thanks
tham
gamebrains


Reply | Threaded
Open this post in threaded view
|

RE: Lua in DLL

Virgil Smith
No prob.
You can pick up a binary from the Wiki if you so choose, or you can DL the
source and make your own (the only real time consumer is making your own
.def file for the exports of the C API).  If you roll your own, you should
give proper credit in the DLL binary (say the version resource) <in addition
to credits in your app etc.>



-----Original Message-----
From: [hidden email]
[[hidden email] Behalf Of Tham
Sent: Tuesday, December 23, 2003 5:59 PM
To: Lua list
Subject: Lua in DLL


hey ya....merry xmas

i'm writing a toolset that has various components (the app, SDK, plugins
etc).... some of these components (the app and some of the plugins) use lua.
to save space i suggested to myself lua in DLL.

is this possible... will there be any issues??

thanks
tham
gamebrains




Reply | Threaded
Open this post in threaded view
|

Re: Lua in DLL

Tham
i figured the def file is gonna be a problem....

i have to do it myself coz we customized some of the lua internals (doubles
to floats etc)...

does any one has a .def file to share???

thanks
tham
gamebrains

----- Original Message ----- 
From: "Virgil Smith" <[hidden email]>
To: "'Lua list'" <[hidden email]>
Sent: Wednesday, December 24, 2003 8:03 AM
Subject: RE: Lua in DLL


> No prob.
> You can pick up a binary from the Wiki if you so choose, or you can DL the
> source and make your own (the only real time consumer is making your own
> .def file for the exports of the C API).  If you roll your own, you should
> give proper credit in the DLL binary (say the version resource) <in
addition
> to credits in your app etc.>
>
>
>
> -----Original Message-----
> From: [hidden email]
> [[hidden email] Behalf Of Tham
> Sent: Tuesday, December 23, 2003 5:59 PM
> To: Lua list
> Subject: Lua in DLL
>
>
> hey ya....merry xmas
>
> i'm writing a toolset that has various components (the app, SDK, plugins
> etc).... some of these components (the app and some of the plugins) use
lua.
> to save space i suggested to myself lua in DLL.
>
> is this possible... will there be any issues??
>
> thanks
> tham
> gamebrains
>
>


Reply | Threaded
Open this post in threaded view
|

RE: Lua in DLL

Virgil Smith
Sending Privately

-----Original Message-----
From: [hidden email]
[[hidden email] Behalf Of Tham
Sent: Tuesday, December 23, 2003 6:17 PM
To: Lua list
Subject: Re: Lua in DLL


i figured the def file is gonna be a problem....

i have to do it myself coz we customized some of the lua internals (doubles
to floats etc)...

does any one has a .def file to share???

thanks
tham
gamebrains

----- Original Message -----
From: "Virgil Smith" <[hidden email]>
To: "'Lua list'" <[hidden email]>
Sent: Wednesday, December 24, 2003 8:03 AM
Subject: RE: Lua in DLL


> No prob.
> You can pick up a binary from the Wiki if you so choose, or you can DL the
> source and make your own (the only real time consumer is making your own
> .def file for the exports of the C API).  If you roll your own, you should
> give proper credit in the DLL binary (say the version resource) <in
addition
> to credits in your app etc.>
>
>
>
> -----Original Message-----
> From: [hidden email]
> [[hidden email] Behalf Of Tham
> Sent: Tuesday, December 23, 2003 5:59 PM
> To: Lua list
> Subject: Lua in DLL
>
>
> hey ya....merry xmas
>
> i'm writing a toolset that has various components (the app, SDK, plugins
> etc).... some of these components (the app and some of the plugins) use
lua.
> to save space i suggested to myself lua in DLL.
>
> is this possible... will there be any issues??
>
> thanks
> tham
> gamebrains
>
>




Reply | Threaded
Open this post in threaded view
|

Re: Lua in DLL

Eric Tetz-2
In reply to this post by Tham
--- Tham <[hidden email]> wrote:
> i figured the def file is gonna be a problem....
> 
> i have to do it myself coz we customized some of the lua
> internals (doubles
> to floats etc)...
> 
> does any one has a .def file to share???

What compiler? Microsoft and Borland both have automated
alternatives to .def files.

__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/

Reply | Threaded
Open this post in threaded view
|

Re: Lua in DLL

Tham
i;m using vc71...

i'm interested with automation.. :)

thanks
tham

----- Original Message ----- 
From: "Eric Tetz" <[hidden email]>
To: "Lua list" <[hidden email]>
Sent: Wednesday, December 24, 2003 8:24 AM
Subject: Re: Lua in DLL


> --- Tham <[hidden email]> wrote:
> > i figured the def file is gonna be a problem....
> > 
> > i have to do it myself coz we customized some of the lua
> > internals (doubles
> > to floats etc)...
> > 
> > does any one has a .def file to share???
> 
> What compiler? Microsoft and Borland both have automated
> alternatives to .def files.
> 
> __________________________________
> Do you Yahoo!?
> New Yahoo! Photos - easier uploading and sharing.
> http://photos.yahoo.com/

Reply | Threaded
Open this post in threaded view
|

Re: Lua in DLL

Eric Tetz-2
--- Tham <[hidden email]> wrote:
> i;m using vc71...
> 
> i'm interested with automation.. :)

Well, if you define LUA_API=__declspec(dllexport) when you build
the DLL, all the appropriate functions will be exported and VC will
create an import library that you can link to any app that uses the DLL.

__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/

Reply | Threaded
Open this post in threaded view
|

Re: Lua in DLL

Tham
excellent....

thanks.
tham

----- Original Message ----- 
From: "Eric Tetz" <[hidden email]>
To: "Lua list" <[hidden email]>
Sent: Wednesday, December 24, 2003 8:33 AM
Subject: Re: Lua in DLL


> --- Tham <[hidden email]> wrote:
> > i;m using vc71...
> > 
> > i'm interested with automation.. :)
> 
> Well, if you define LUA_API=__declspec(dllexport) when you build
> the DLL, all the appropriate functions will be exported and VC will
> create an import library that you can link to any app that uses the DLL.
> 
> __________________________________
> Do you Yahoo!?
> New Yahoo! Photos - easier uploading and sharing.
> http://photos.yahoo.com/

Reply | Threaded
Open this post in threaded view
|

Re: Lua in DLL

Peter Hill-3
In reply to this post by Virgil Smith
gamebrains:
> to save space i suggested to myself lua in DLL.
> is this possible... will there be any issues??

Virgil Smith:
> No prob.
> You can pick up a binary from the Wiki if you so choose,

Sounds interesting. Where in the Wiki? I had a look but couldn't see it.

*cheers*
Peter Hill.



Reply | Threaded
Open this post in threaded view
|

Re: Lua in DLL

Jamie Webb-3
In reply to this post by Eric Tetz-2
On Wednesday 24 December 2003 00:33, Eric Tetz wrote:
> --- Tham <[hidden email]> wrote:
> > i;m using vc71...
> >
> > i'm interested with automation.. :)
>
> Well, if you define LUA_API=__declspec(dllexport) when you build
> the DLL, all the appropriate functions will be exported and VC will
> create an import library that you can link to any app that uses the DLL.

IIRC though, you should be aware that the DLL will not be quite conventional 
if you compile as C++ using this method: the DLL will use the mangled names, 
which are a nuisance from e.g. VB.

 -- Jamie Webb

Reply | Threaded
Open this post in threaded view
|

Re: Lua in DLL

Wim Couwenberg-4
> IIRC though, you should be aware that the DLL will
> not be quite conventional 
> if you compile as C++ using this method: the DLL
> will use the mangled names, 
> which are a nuisance from e.g. VB.

Place #include <lua.h> in an extern "C" block, or
alternatively #define LUA_API extern "C"
__declspec(dllexport)

--
Wim


__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/

Reply | Threaded
Open this post in threaded view
|

Re: Lua in DLL

Wim Couwenberg-4
> Place #include <lua.h> in an extern "C" block, or
> alternatively #define LUA_API extern "C"
> __declspec(dllexport)
> 

This will prevent C++ mangling, not the "_" (and "@")
mangling that comes with __cdecl (and __stdcall),
which is what Jamie probably meant.  Sorry...

--
Wim


__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/