lua-users home
lua-l archive

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


1: Strings are pooled by Lua, so moving them between variables or
passing them into functions doesn't make a copy of the string, but
re-use the existing string.

2: Personally, I call a table whose keys will be 1 .. N, an array.
Other people will have other names for it.

3 C functions: There cannot be C functions in the stack between the
calls to resume and yield. Therefore you cannot yield inside a
function given to table.sort to a resume outside the function, because
table.sort is a C function.

3 iterators and metamethods: Like you cannot have a call to a C
function in the stack between resume and yield, neither can you have a
function being called by 'for' (although you can yield from the body
of the for loop) nor a function being called as a metamethod.

2008/6/30 Veli-Pekka Tätilä <vtatila@gmail.com>:
> Hi,
> Sorry to bother you again. This is the third and final post from me for a
> little while, haha. These are partly implementation and convention
> questions, I guess, and there are a couple:
>
> 1. PIL 1st ed says strings are immutable and any changes make a copy of a
> string. The ref manual  also says only tables are passed by reference. Does
> that mean that a string is needlessly copied by value when I pass it to a
> function (ala Perl if you copy args to my variables in that language)? one
> would think it wouldn't have to be. That is if you only access a string as a
> parameter, then surely you don't need a separate copy. And even if you tried
> to modify it, that modification would yield a new string, i.e. there's no
> fear of clobbering the original.
>
> 2. What should I call tables indexed by a continuous range of ints as
> opposed to arbitrary strings in documenting functions? In Perl you have the
> terms array and hash. In Lua most folks talk about tables but that's sort of
> ambiguous. I'd be tempted to call tables indexed by int lists, but Perl uses
> the term list specially, and even in Lua it mostly brings to mind list
> assignments and vararg lists. Does it make sense to use the terms array,
> record, hash and sparce array depending on whether you'll use the table for
> storing elems by int indeces, named fields, looking up stuff by arbitrary
> data or storing noncontiguous runs of int indexed elements?
>
> 3. There's a bit in the ref man about coroutines I'd like clarified:
>
> Quote about yield:
> Suspends the execution of the calling coroutine. The coroutine cannot be
> running a C function, a metamethod, or an iterator.
> End quote.
>
> Umm what's this about? Surely you can do iterators using coroutines or even
> yield in the middle of a for in statement, right? Does the C function bit
> have any relevance if I'm only using Lua. SUrely if I call a C function I
> cannot do anything before it returns anyway. Howabout Lua code that is
> called from a C app, If I got it right, that's still eligible for using
> coroutines normally.
>
> I think I've fundamentally misunderstood something in the above brief
> description, oh well. Lists like these are great for clarifying points such
> as this.
>
> --
> With kind regards Veli-Pekka Tätilä
> Accessibility, Apps and Coding plus Synths and Music:
> http://vtatila.kapsi.fi
>
>