[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: RES: Lua in JavaScript
- From: Jay Carlson <nop@...>
- Date: Sun, 16 Sep 2007 18:22:09 -0700
--
Jay
Sent from a Treo, excuse infelicities
-----Original Message-----
From: "Rafael - SosCpdTerra" <soscpd@terra.com.br>
To: "'Lua list'" <lua@bazar2.conectiva.com.br>
Sent: 7/25/07 1:34 PM
Subject: RES: Lua in JavaScript
We must consider having many browsers support such the most used ones, like
FF(yes, fat and slow), explorer(unsafe and not standard, but fast), opera(my
download choice too) and Safari(no comments...), if not all them (I think
that is the easy way.). My point is: Think our point must not be what
browser support. Must be how technology is so deep in actual DOM and open
enough to use it and write the binding. Start working with explorer or
firefox or whatever browser we choose is expect the browser companies see
the potential and use it. Safari use Lua!!! I don't know how... yet. A first
step can be just research and plan what can be done. Brain storm. Later we
filter what cant be used. A project... goals, etc... but not a workflow...,
please... I have just my free time to work on that.
Think a good start is stop the noise on the list.
I can be directly find at rafael@soscpd.wiki.br, any time.
We can host the project somewhere.
Here is the safari lua file contents:
-- Main entry point for PubSub template expansion
local format = string.format
local gsub = string.gsub
local find = string.find
local strsub = string.sub
local concat = table.concat
local tinsert = table.insert
local compiledTemplates = {}
-- shortcut for localized strings; just use LOC.kSomeKey or LOC['kSomeKey']
LOC = {}
locmeta = {}
function locmeta.__index(table,key)
local value = pubsub.getLocalizedString(key)
assert(value, "No localized string")
rawset(table,key,value) -- cache the value, for performance
return value
end
setmetatable(LOC,locmeta)
-- escape a string for substitution in HTML text
local kHTMLMap = {['<'] = '<', ['>'] = '>', ['&'] = '&', ['"'] =
'"', ["'"] = ''' }
function escape( str )
if str then
return string.gsub(str, '([<>&"\'])', function(chr)
return kHTMLMap[chr]
end)
else
return str
end
end
local function out (s, i, f)
s = strsub(s, i, f or -1)
if s == "" then return s end
-- we could use `%q' here, but this way we have better control
s = gsub(s, "([\\\n\'])", "\\%1")
return format(" emit('%s'); ", s)
end
function translate (s)
s = gsub(s, "<%%(.-)%%>", "<?lua %1 ?>")
local res = {}
local start = 1 -- start of untranslated part in `s'
while true do
local ip, fp, target, exp, code = find(s, "<%?(%w*)[
\t]*(=?)(.-)%?>", start)
if not ip then break end
tinsert(res, out(s, start, ip-1))
if target ~= "" and target ~= "lua" then
-- not for Lua; pass whole instruction to the output
tinsert(res, out(s, ip, fp))
else
if exp == "=" then -- expression?
tinsert(res, format(" emit(%s);", code))
else -- command
tinsert(res, format(" %s ", code))
end
end
start = fp + 1
end
tinsert(res, out(s, start))
return concat(res)
end
-- Compile the contents string and store the resulting function in
compiledTemplates[name]
function compileTemplate (name, contents)
local prog = "return function(emit, model)\n" .. translate(contents) .
"\nend"
local code,err = loadstring(prog);
if code then
local f = code();
compiledTemplates[name] = f;
else
error(err);
end
end
-- Run the named precompiled template, with the given model
function applyTemplate (name, model)
local f = compiledTemplates[name]
if not f then
error("template " .. name .. " not compiled");
end
local resultStrings = {};
local function collectOutput(str)
if str then
tinsert(resultStrings, tostring(str))
end
end
f(collectOutput, model) -- SHAZAM! Evaluate the compiled
template
return concat(resultStrings)
end
-----Mensagem original-----
De: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] Em nome de Ketmar Dark
Enviada em: quarta-feira, 25 de julho de 2007 18:02
Para: lua@bazar2.conectiva.com.br
Assunto: Re: Lua in JavaScript
On Wed, 25 Jul 2007 16:42:37 -0300
"Rafael - SosCpdTerra" <soscpd@terra.com.br> wrote:
> Im sure your Opera can work with plugins... if macromedia can do flash
> plugin and java can do plugin too, WE CAN DO PLUGIN!!! :)
yes.
> A fact on this project must be: Lua in browser. Yes, I think java can
> be used, but is not my way of lightweight. We must consider search
> for other ways to do so. I will love if we use Lua as dynamic link
> library for windows and linux. Our job must be simply grant to the
> browsers, access to lua language, such javascript. I will search more
> information before say there are other projects or not, or how can we
> do that.
but... Java and Flash plugins has no access to DOM. there are just
"windows" with their own controls, etc... there's no way to control DOM
as JS do. %-(
and NS plugin API is very restricted, afair. i'll google to refresh
my memories. %-)
sure, we can patch FF to use either JS or Lua as scripting language,
but Opera is closed source software... and Explorer... argh, i don't
want to talk about Explorer, albeit i nearly sure that IE can use Lua
exactly in this way thru Windows Scripting Host... %-))
and i don't like FF too (it is too fat and too slow %-( ). and anyway,
embedding Lua with the same abilities JS have means separate branch of
developing and constant patching... but i'm not an expert in FF. if we
can do thi only in FF -- this will be fine. *something* is definetely
better than *nothing*. %-))