On Tue, Mar 15, 2011 at 08:05, Dan Poirier <[email protected]> wrote:
> On Tue. 2011-03-15 at 09:36 AM EDT, HyperHacker <[email protected]> wrote:
>
>> I've been eagerly looking forward to a stable mod_lua with which to
>> make my sites. If done well, Lua could replace PHP as the #1 web
>> scripting language
>
> Maybe if people could embed lua in web pages.
>
Mm, personally I dislike the "embed code in HTML" thing, as I'm one of
those purists who likes to keep code, presentation, and data separate.
However I did, just for fun, write a web server in Lua which had that
capability. It basically just did a gsub on the HTML file being sent:
str = str:gsub('<%?lua%s.-%s%?>',
function(code)
local func = loadstring(code:sub(7, -4))
setfenv(func, self.Request.Environment)
return tostring(func())
end)
This is one of the things I love about Lua - once you have the
language, whatever additional functionality you want can be
implemented pretty easily. Little is built in. I imagine you could
work this into your mod_lua configuration fairly easily, and there you
go, code embedded within pages.
--
Sent from my toaster.