:: Re: [DNG] Lua
Página superior
Eliminar este mensaje
Responder a este mensaje
Autor: onefang
Fecha:  
A: dng
Asunto: Re: [DNG] Lua
On 2024-10-18 02:06:46, Steve Litt wrote:
> Hendrik Boom said on Thu, 17 Oct 2024 09:59:49 -0400
>
> >On Thu, Oct 17, 2024 at 12:30:49PM +0200, Didier Kryn wrote:
> >
> >> I remember Lua as a pretty decent high level language
> >
> >a bit like a Lisp with syntax and fewer parentheses.xc
> >
> >My daughter uses Lua preferentially. I find her code hard to read.
>
> The trick to easy reading of Lua is that the one and only data
> structure is the table, which is an unordered list of key/value pairs.
> The preceding sentence isn't completely true, but it's a good starting
> point.


Good starting point.

> Lua tables are so efficient that they can substitute for arrays, simply
> by making the keys 0 thru whatever.


Technically you can use 0 as a key, but in general Lua counts from 1, not
from 0 like a lot of other languages. There is support for treating them
like arrays, and you can mix both in one table. A table defined with
just a list of values and no keys gets the keys 1 through whatever by
default. Or sprinkle in ones without and with keys, the keyless ones get
consecutive integers as the defult key.

> A second Lua data structure is the metatable, which I still can't
> exactly understand.


The general idea behind metatables is that if you access a table that has
one, the metatable portion gets to redirect your access. So the value
part of the key/value pair might be computed each time you read it for
example. Writing a value to a specific key might trigger a database
update as another example.

You can do a lot without dealing directly with metatables, by as you said
sticking mostly with tables.

--
A big old stinking pile of genius that no one wants
coz there are too many silver coated monkeys in the world.