_G equilence in Lua 4

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

_G equilence in Lua 4

Fabrício de Alexandria
Hi everyone, 


I was developing scripts in Lua 5 and now I have to make them work with 
Lua 4 version. I'm using _G variable and I don't know the equivalent in 
Lua 4. 

Fabricio
											


Reply | Threaded
Open this post in threaded view
|

Re: _G equilence in Lua 4

Jamie Webb-3
On Thursday 22 April 2004 14:36, Fabricio de Alexandria wrote:
> Hi everyone,
>
>
> I was developing scripts in Lua 5 and now I have to make them work with
> Lua 4 version. I'm using _G variable and I don't know the equivalent in
> Lua 4.

globals()

-- Jamie Webb

Reply | Threaded
Open this post in threaded view
|

Re: _G equilence in Lua 4

Fabrício de Alexandria
Thanks. I thought this was related to what I want. I've already had a look 
at this in the manual but I just found the set/getglobal. I don't know if 
I understood what this functions do but I think this is not what I'm 
looking for. They get/set values of a global variable. I want to change a 
function and introduce new instructions on it.

This is what I want to do. I have a function called test() and I want to 
change it.

function test()
  print 'test'
end

function change( f )
	table = _G

	local old_fn = table[f]
	table[f] = function( ... )
			print "function changed"
			return (old_fn)(unpack( arg ))
	     end end

print 'before change' 
test() 
print 'after change' 
change ('test')
test()

And I get this:

before change
test
after change
function changed
test

What could be the equivalent code in Lua 4?

Fabricio

On Thu, 22 Apr 2004, Jamie Webb wrote:

> On Thursday 22 April 2004 14:36, Fabricio de Alexandria wrote:
> > Hi everyone,
> >
> >
> > I was developing scripts in Lua 5 and now I have to make them work 
with
> > Lua 4 version. I'm using _G variable and I don't know the equivalent 
in
> > Lua 4.
>
> globals()
>
> -- Jamie Webb
>


Reply | Threaded
Open this post in threaded view
|

Re: _G equilence in Lua 4

Edgar Toernig
Fabricio de Alexandria wrote:
>
> What could be the equivalent code in Lua 4?

+ _G = globals()

  function test()
    print 'test'
  end
  
  function change( f )
  	table = _G
 
  	local old_fn = table[f]
  	table[f] = function( ... )
  			print "function changed"
-			return (old_fn)(unpack( arg ))
+                       return call(%old_fn, arg)
  	     end end
 
  print 'before change' 
  test() 
  print 'after change' 
  change ('test')
  test()


Ciao, ET.