jit/util.funck

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(Clarification)
(Added note about protos)
Line 19: Line 19:
 
{{Ret
 
{{Ret
 
|type=any
 
|type=any
|desc=the constant found
+
|desc=The constant found.
 +
 
 +
{{Note|This will return a {{Type|proto}} for functions that are created inside the target function - see Example 2.}}
 
}}
 
}}
 
{{Example
 
{{Example
Line 29: Line 31:
 
print(jit.util.funck(bob, -1))
 
print(jit.util.funck(bob, -1))
 
print(jit.util.funck(bob, -2))
 
print(jit.util.funck(bob, -2))
|Output="print"
+
|Output=print<br>
"hi"
+
hi
 +
}}
 +
{{Example
 +
|Description=Demonstrates how a function created inside of the accessed function will be a {{Type|proto}}s when used with this function.
 +
|Code=local function foo()
 +
    local function bar()
 +
    end
 +
end
 +
 
 +
print( type( jit.util.funck( foo, -1 ) ) )
 +
|Output=proto
 
}}
 
}}

Revision as of 21:36, 18 November 2019

 jit.util.funck( )

Contents

Description

Gets a constant at a certain index in a function.

WARNING

This function isn't officially documented on LuJIT wiki, use it at your own risk.

WARNING

Numbers constants goes from 0 (included) to n-1, n being the value of nconsts in jit.util.funcinfo in other words, the consts goes from (nconsts-1) to -n

NOTE

This function only works for Lua defined functions.

Arguments

function func

Function to get constant from

Arguments

number index

Constant index (counting down from the top of the function at -1)

Returns

any

The constant found.

NOTE

This will return a proto for functions that are created inside the target function - see Example 2.

Examples

Example

This code demonstrates how to get a constant in a function.

function bob()
    print("hi")
end

print(jit.util.funck(bob, -1))
print(jit.util.funck(bob, -2))

Output:

print
hi

Examples

Example

Demonstrates how a function created inside of the accessed function will be a protos when used with this function.

local function foo()
    local function bar()
    end 
end

print( type( jit.util.funck( foo, -1 ) ) )

Output:

proto
Personal tools
Navigation