lua-users home
lua-l archive

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

on 8/16/05 5:50 AM, Mike Pall at wrote:

> Right now all suggestions go for the first alternative.
> If there was a standard preprocessor for Lua, the obvious
> thing to do would be to define the following substitutions:
> import "a.b.c"
>   ==>
> local c = require "a.b.c"
> import("a.b.c", d, e, f)
>   ==>
> local c = require "a.b.c"
> local d, e, f = c.d, c.e, c.f
> Realistic examples:
> import("math", sin, cos, tan)
> import("string", sub, gsub, find, gfind)
> Yes, the standard parser could do this, too. It would be a bit
> unorthogonal, but tremendously useful. Would've saved me a lot
> of typing (and typos).

I like that. Our import function does essentially that but it can't declare
the locals and hence that functionality doesn't get used much.

This and other discussions are leading to a distinction between interactive
Lua and script Lua.

Interactive Lua: require/import loads into the global namespace which is
probably  a sandbox for the interactive environment; global access is
considered perfectly reasonable

Script Lua: require/import loads into locals; globals need to be explicitly
declared via a "global" keyword, but since there are few if any globals this
probably needs to be used at most rarely

Having such a distinction doesn't seem desirable at first, but when one
considers that the execution circumstances and needs are inherently
different it doesn't seem completely irrational.