lua-users home
lua-l archive

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

On Thu, Nov 09, 2006 at 09:27:55AM +0800, Simon Wittber wrote:
> On 11/9/06, Thomas Lefort <> wrote:
> >Do you really need threads ? Or can you solve concurrency issues by
> >softer means ?
> I'm primarily interested in exploiting multi-core architectures in a
> high level language, like Lua. Not many dynamic, high level languages,
> support genuine concurrency across multiple CPUs/cores. I've
> investigated Ruby, Python, and a few Scheme dialects.

Yes, its a strength of lua, even though you'll continually hear the "use
coroutines instead" refrain.

> >> What is the purpose of using the local keyword in the global scope?
> >
> >Same as in any scope, why ?
> Ah, I didn't understand that each file (which I know know as a
> 'chunk') has it's own scope. I understand what this does now.

It's only a chunk after you load it...

local intruduces a new lexically scoped variable. Try:

local foo = 4

-- function's use of foo is bound to the one above
function p() print(foo) end

-- this also uses that foo
foo = 5

-- so this prints 5

-- but this made a new local called foo
local foo = 6

-- which is unrelated to the foo seen by function p, and which
-- function p still refers to, even though it is no longer in
-- the current "scope"