lua-users home
lua-l archive

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


I am aware of this section of the FAQ, however I cannot get this to work.
>From my understanding of this code, adding this code to the begining of a
script should be all I need?

eg?

function safe_getglobal(x)
  local v=rawgetglobal(x)
  if v then return v else error("undefined global variable "..x) end
end

settagmethod(tag(nil),"getglobal",safe_getglobal)

x = 10


This should cause the function safe_getglobal to be run, because of the
assignment to global x?  It doesn't seem to run for me?  What am I doing
wrong?  Also I would like this code to be done in C and not from within the
script.

Chris Percival
Software Engineer
Interaxis Computing Ltd.
DDI:  +44 (0)1249 700072
http://www.interaxis.co.uk/

> -----Original Message-----
> From: owner-lua-l@tecgraf.puc-rio.br
> [mailto:owner-lua-l@tecgraf.puc-rio.br]On Behalf Of Luiz Henrique de
> Figueiredo
> Sent: 31 January 2002 12:01
> To: Multiple recipients of list
> Subject: Re: Variable declaration
>
>
> >Is there a quick and easy way of making a lua script require variable
> >declarations.
>
> For globals, see FAQ 3.1.
> --lhf