lua-users home
lua-l archive

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



_G['?'] was simply a way of showing, the syntax filter makes calls to a '?' global function (addressable as _G['?'] since _G has the globals). Such function is trivial (test-tricond.lua has one), but needs to be provided from outside of the token filter.

-- This func needed by the token filter
_G["?"]= function( cond )
  return function(tbl)
assert( tbl, "Usage: ? cond { true_choice, false_choice }" )
            if cond then return tbl[1]
            else         return tbl[2]
            end
         end
end

I have no experience on Lisp/Scheme macros, leaving that for others to answer (see Lua list archives..)

Agreeing with you, the Lua community is about as great as the language. BIG HAND for the all of us! ;D

-asko


therandthem kirjoitti 7.11.2006 kello 23.06:

Your additional explaination was very much
appreciated.   I didn't realize that lua did not have
the C style operators and now it makes perfect sense.

On ? cond {true_choice, false_choice} can you explain
a bit more about what _G['?'](cond){ true_choice,
false_choice } is doing?  Is _G['?'] making '?' a
token?  If so, what is happenning in the parensthesis
that would make it choose one of the items in the
braces?  Sorry to try and get a little Lua tutorial
out of this :)

How does this compare with Lisp/Scheme macros?  Have
you seen www.livelogix.net?  It does a little macro
action on Python to extend syntax.

I'll be honest.  I've been watching Lua for a few
years and haven't been very interested in it's syntax.
 However, I have been very impressed by its community
and the runtime performance.  I see Lua as a great
runtime platform.  Anything that opens up its syntax
is exactly what interests me.

Thanks,

McKinley

--- Asko Kauppi <askok@dnainternet.net> wrote:


Yes, thanks for asking.

It is not really a patch, but a set of "token
filters" to be used
with LHF's earlier patch.

Tokens are the first level parsed version of your
Lua code; between
source code and Lua bytecode. They are normally only
handled
internally, but token filter patch allows one to
insert his/her
custom rules, to change the way Lua syntax is.

The elegancy lies in being able to adapt the
language, without
changing the C code a bit. Therefore, this allows
extensions/mods to
be used by anyone, anywhere, on any system. This is
all background,
presentation of what "token filtering" itself is.

Usage:
	lua -lfilter yourcode.lua

Loading filter.lua prepares Lua to load the real
code, using the
better/worse/different syntax.

Now, to my packet:

ftools.lua
	- higher level interface for making token filters
	- ability to have multiple filters, loaded from
separate files
(maybe multiple authors)

ftricond.lua
      ? cond { true_choice, false_choice }	The
ternary operator, as
in C/Perl

fselect.lua
      #...        -> select('#',...)	Shorthand and
more readable to
managing multiple
      ...[n]      -> (select(n,...))	parameter lists
(...)

finc.lua
      exp +=  -> exp = exp +		C-style += operations:
  myvar += 1
      exp -=  -> exp = exp -
      exp *=  -> exp = exp *
      exp /=  -> exp = exp /
      exp ..=  -> exp = exp ..

fdotuntil.lua
      tbl.until etc.			Normally, Lua does not allow
"until", "function",
					"repeat", "true", "false", "nil" as table
indices.

There's no harm in using these mods, any valid Lua
code will run with
the filters applied as well. The purpose of token
filtering, by lhf
was to give a testing ground for custom syntax
changes, some of which
might make it to future Lua proper. Based on my
experiences, token
filtering is Simply Great for this, and will reduce
the need for
special this-and-that patches by a magnitude.

-asko



therandthem kirjoitti 7.11.2006 kello 1.09:

I'm new to Lua and do not totally understand the
basic
syntax, let alone this patch you describe.  Could
you
provide a simpler overview of what you are
describing
here?

Thanks,

McKinley

--- askok@dnainternet.net wrote:


Attached is a set of token tuning tools, and some
tune-ups, to give your Lua a flashy, almost
syntax-over-sugary look.
I don't promise furry backseats, no built-in XBox
360, but
almost. :)

Requirements:
      Lua 5.1 with token filter patch applied
(not
included)

Ignition:
      make LUA=path-to-your-modded/lua

Tested on:
      OS X 10.4 (but there's nothing system
specific)

Gains:
     ? cond { true_choice, false_choice }   -->
 _G['?'](cond){ true_choice, false_choice }
     #...        -> select('#',...)
     ...[n]      -> (select(n,...))
     exp +=  -> exp = exp +
     exp -=  -> exp = exp -
     exp *=  -> exp = exp *
     exp /=  -> exp = exp /
     exp ..=  -> exp = exp ..
     tbl.until          (and other reserved
words:
function, repeat, nil, false, true)
     {|, until=
     obj:until
     =|,|(|{ do  -> =|,|(|{ function()

The important part really is the ftools.lua,
which
allows
multiple filters to co-operate, without need to
know
of
each other. As to my knowledge, this hasn't been
possible
earlier.

-asko








______________________________________________________________________

______________
Sponsored Link

$200,000 mortgage for $660/mo - 30/15 yr fixed,
reduce debt, home
equity -
Click now for info
http://yahoo.ratemarketplace.com







______________________________________________________________________ ______________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail.
http://new.mail.yahoo.com