Deref: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ {{Server client function}} This function will take a reference returns its Lua element. ==Syntax== <syntaxhighlight lang="lua"> mixed deref( int reference )...")
 
No edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Server client function}}  
{{Server client function}}  
This function will take a reference returns its Lua element.
This function will take a reference obtained by the [[ref]] function and returns its Lua element.


==Syntax==  
==Syntax==  
Line 13: Line 13:
===Returns===
===Returns===
Returns ''mixed'' if the reference were valid. Returns ''false'' if the reference were invalid.
Returns ''mixed'' if the reference were valid. Returns ''false'' if the reference were invalid.
==Remarks==
This function was originally created to prevent garbage-collection of specific Lua objects/elements which should persist even though no script would reference them. The storage of those references can be obtained by a call to the debug.getregistry function. The '''ref''' and '''deref''' template can easily be remade using a locally-hidden Lua table and two such function implementations.


==See Also==
==See Also==
{{Utility functions}}
{{Utility functions}}

Latest revision as of 17:02, 20 October 2021

This function will take a reference obtained by the ref function and returns its Lua element.

Syntax

mixed deref( int reference )    

Required Arguments

  • reference: The valid reference, which you want to dereference

Returns

Returns mixed if the reference were valid. Returns false if the reference were invalid.

Remarks

This function was originally created to prevent garbage-collection of specific Lua objects/elements which should persist even though no script would reference them. The storage of those references can be obtained by a call to the debug.getregistry function. The ref and deref template can easily be remade using a locally-hidden Lua table and two such function implementations.

See Also