lua-users home
lua-l archive

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


Quoting PA <petite.abeille@gmail.com>:

> lua: TestXML.lua:56: `in' expected near `='
> 
> What would be the proper syntax then?

my mistake, use 'in' instead of '=' (that's a mistake i repeat all the time)

> One way or another, I need to read more about this fabled generic for 
> loop.

you won't regret it.  iterators are a great way to traverse anything, specially
when done with coroutines (i think they're called 'generators' in that case?)

> > it's a very small point, but i mention it, because in general i've seen
> > your code is well structured, but very 'unlua', making it less 
> > efficient
> > and less useful to others
> 
> First... make it work... then... perhaps... make it work well...

it's not an optimization, it's more a mindframe thing.  in low level languages
you mostly choose your algorithms, but in higher level it's important to see
what the language offers you and follow the path of least resistance.

.... unless you want a good fight! ;-)

> >   I don't want to reignite the discussion about OOP vs FP vs anything 
> > else; just
> > remember that not everything has to be an object.
> 
> Sure. Same applies for random piles of functions.

yep.  and there are lots of things done best with an object (i think a XML pull
parser IS one of them)

personally, i do use object-like constructs in Lua all the time.  i like the
obj:func() form, and since i seldom use any inheritance, i haven't find the need
for a full OOP scheme in Lua.

Even in C++, the data-managing parts of my programs are very shallow class
hierarchies.  the GUI parts do get deep... but mostly because of the framework i
happen to use.

> But frankly speaking, I haven't seen a great deal of reuse in Lua. At 
> all. Quite a let down, if you ask me. And here I am writing a dumb 
> little function to decode XML strings. Duh.

very true.  i think code reuse is more at a module level than at object or
function level.

and at the copy-paste level, of course!

> Because I'm not sure what this fabled "Lua way" is. Concrete suggestion 
> warmly welcome :)

rici's example is a nice one (much better than mine!)
concrete 'luaisms' used on his decoder:

- wrap a small module on a do...end block, so a single function is exported
(decode()), but it has access to local vars (ents[] and maxutf8) and functions
(entity2char())
- use a lookup table
- use a standard function (gsub()), and give it another function as a parameter
- use 'str and gsub(....)' idiom to check parameters before using them

>......
> local aValue = thisClass.entities().get( anEntity ) 
>........
>Is that Lua-esque enough? :)) 

is that line a lookup table? if so, why not use tables???

------
Javier