Couple of technical questions

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Couple of technical questions

Peter Hill-2
(1) I have seen it mentioned that "setglobals" does not work on native C
functions and I was wondering why. Is this by design? Or is it due to
technical difficulties?

(2) Why do metamethods have a double underscore prefix? That seems to imply
that the metatable will be filled with other, otherwise conflicting,
entries.

*cheers*
Peter Hill.

Ki: Contractors... high-paid leeches stealing our work.
Fooker: If you think of them as disposable employees, you'll feel much
better...



Reply | Threaded
Open this post in threaded view
|

RE: Couple of technical questions

Benoit Germain
a metatable can be filled with whatever you want. I am currently using this
feature to implement a scheme similar to the proxy mechanism: a full
userdata comes with a metatable that contains __index and __nexindex
functions that get and set fields in the metatable itself (in addition to
fetching predefined members as well). That way, the full userdata can be
used as any regular table.

-----Message d'origine-----
De : Peter Hill [[hidden email]]
Envoyé : mardi 18 février 2003 04:59
À : Multiple recipients of list
Objet : Couple of technical questions


(2) Why do metamethods have a double underscore prefix? That seems to imply
that the metatable will be filled with other, otherwise conflicting,
entries.

*cheers*
Peter Hill.

Ki: Contractors... high-paid leeches stealing our work.
Fooker: If you think of them as disposable employees, you'll feel much
better...


Reply | Threaded
Open this post in threaded view
|

Re: Couple of technical questions

Peter Hill-2
Peter Hill:
> (2) Why do metamethods have a double underscore prefix? That seems to
imply
> that the metatable will be filled with other, otherwise conflicting,
> entries.

Benoit Germain:


> a metatable can be filled with whatever you want. I am currently using
this
> feature to implement a scheme similar to the proxy mechanism: a full
> userdata comes with a metatable that contains __index and __nexindex
> functions that get and set fields in the metatable itself (in addition to
> fetching predefined members as well). That way, the full userdata can be
> used as any regular table.

Wouldn't it be better to use a separate table as the proxy? That way it
could store any values (even "__blah" ones) without unexpected consequences.

*cheers*
Peter Hill.

Ki: Contractors... high-paid leeches stealing our work.
Fooker: If you think of them as disposable employees, you'll feel much
better...



Reply | Threaded
Open this post in threaded view
|

RE: Couple of technical questions

Benoit Germain
In reply to this post by Peter Hill-2
It is not a problem for me, end users will be told not to use "__" to prefix
their own variables. I have a hammer and baseball bat on my desk to enforce
this :-)

-----Message d'origine-----
De : Peter Hill [[hidden email]]
Envoyé : mardi 18 février 2003 10:37
À : Multiple recipients of list
Objet : Re: Couple of technical questions


Peter Hill:
> (2) Why do metamethods have a double underscore prefix? That seems to
imply
> that the metatable will be filled with other, otherwise conflicting,
> entries.

Benoit Germain:


> a metatable can be filled with whatever you want. I am currently using
this
> feature to implement a scheme similar to the proxy mechanism: a full
> userdata comes with a metatable that contains __index and __nexindex
> functions that get and set fields in the metatable itself (in addition to
> fetching predefined members as well). That way, the full userdata can be
> used as any regular table.

Wouldn't it be better to use a separate table as the proxy? That way it
could store any values (even "__blah" ones) without unexpected consequences.

*cheers*
Peter Hill.

Ki: Contractors... high-paid leeches stealing our work.
Fooker: If you think of them as disposable employees, you'll feel much
better...


Reply | Threaded
Open this post in threaded view
|

Re: Couple of technical questions

Wim Couwenberg-2
In reply to this post by Peter Hill-2
Hi,

> > (2) Why do metamethods have a double underscore prefix? That seems to
> imply
> > that the metatable will be filled with other, otherwise conflicting,
> > entries.

Another reason was that you can quickly locate "meta related" pieces of code
by scanning for double underscores.  (More so if enforced by blunt
intstruments  ;-)

Bye,
Wim



Reply | Threaded
Open this post in threaded view
|

Error recovering

jose marin2
Hello!

When Lua finds some error in my code, the entire application crashes!

How do you handle errors in Lua scripts?

Is there a function that shuts down Lua when needed?




Reply | Threaded
Open this post in threaded view
|

Re: Error recovering

Dimitris Papavasileiou
Hi,
what I do to load a file is this:

    if(luaL_loadfile(l, name) || lua_pcall(l, 0, 0, 0))
        return error((char *) lua_tostring(l, -1));
    else
        return 1;

error() is just a macro that prints a formatted string and returns 0.I
assume similar things can be done for strings etc.

Dimitris


Reply | Threaded
Open this post in threaded view
|

Re: Couple of technical questions

Björn De Meyer
In reply to this post by Benoit Germain
Benoit Germain wrote:
> 
> It is not a problem for me, end users will be told not to use "__" to prefix
> their own variables. I have a hammer and baseball bat on my desk to enforce
> this :-)
> 

Even more efficient is to have your __index and __newindex explicitly 
check their arguments and refuse to set any key that begins with "__".
Twenty minutes of programming is much faster than twenty years in jail. 
^_~

-- 
"No one knows true heroes, for they speak not of their greatness." -- 
Daniel Remar.
Björn De Meyer 
[hidden email]