debug/setupvalue

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(Created page with "{{Func |Name=setupvalue |Parent=debug |Description= |Realm=Shared |IsClass=No }} ")
 
(Added information to the function)
Line 2: Line 2:
 
|Name=setupvalue
 
|Name=setupvalue
 
|Parent=debug
 
|Parent=debug
|Description=
+
|Description=Sets the variable indexed by 'up' from function 'f' to 'newValue'.
 
|Realm=Shared
 
|Realm=Shared
 
|IsClass=No
 
|IsClass=No
 +
}}
 +
{{Arg
 +
|type=function
 +
|name=f
 +
|desc=The function to index the upvalue from.
 +
}}
 +
{{Arg
 +
|type=number
 +
|name=up
 +
|desc=The index upwards from the function f.
 +
}}
 +
{{Arg
 +
|type=any
 +
|name=newValue
 +
|desc=The value to set the upvalue to.
 +
|default=nil
 +
}}
 +
{{Ret
 +
|type=string
 +
|desc=Returns nil if there is no upvalue with the given index, otherwise it returns the upvalue's name.
 +
}}
 +
{{Example
 +
|Description=An example demonstrating a function overwrite.
 +
|Code=local function my_isfunction(f)
 +
return type(f) == "function" or f == "coolguy"
 +
end
 +
 +
print(debug.setupvalue(hook.Add, 1, my_isfunction))
 +
|Output=isfunction
 
}}
 
}}

Revision as of 13:32, 21 January 2015

 debug.setupvalue( )

Contents

Description

Sets the variable indexed by 'up' from function 'f' to 'newValue'.

Arguments

function f

The function to index the upvalue from.

Arguments

number up

The index upwards from the function f.

Arguments

any newValue=nil

The value to set the upvalue to.

Returns

string

Returns nil if there is no upvalue with the given index, otherwise it returns the upvalue's name.

Examples

Example

An example demonstrating a function overwrite.

local function my_isfunction(f)
	return type(f) == "function" or f == "coolguy"	
end

print(debug.setupvalue(hook.Add, 1, my_isfunction))

Output:

isfunction
Personal tools
Navigation