Userdata: Difference between revisions
From Legacy Roblox Wiki
Jump to navigationJump to search
>Blocco Most people looking at the wiki like contractions, especially in this case. |
>JulienDethurens No edit summary |
||
Line 2: | Line 2: | ||
==Userdata== | ==Userdata== | ||
===What is a Userdata?=== | ===What is a Userdata?=== | ||
A userdata is the type Lua uses for data structures in the underlying C program. There aren't native Lua functions for handling those types, they must be handled via [[ | A {{type|userdata}} is the type Lua uses for data structures in the underlying C program. There aren't native Lua functions for handling those types, they must be handled via [[metatables]]. All Roblox objects and events are {{type|userdata}} Lua type. | ||
===Using Userdatas=== | ===Using Userdatas=== | ||
You can create a new userdata by passing true to the undocumented newproxy function. This userdata cannot be used for anything other than invoking functions via its metatable. | You can create a new {{type|userdata}} with an empty metatable by passing true to the undocumented [[newproxy]] function. This {{type|userdata}} cannot be used for anything other than invoking functions via its metatable. | ||
{{Example|<pre> | {{Example|<pre> |
Revision as of 22:39, 12 February 2012
Userdata
What is a Userdata?
A userdata is the type Lua uses for data structures in the underlying C program. There aren't native Lua functions for handling those types, they must be handled via metatables. All Roblox objects and events are userdata Lua type.
Using Userdatas
You can create a new userdata with an empty metatable by passing true to the undocumented newproxy function. This userdata cannot be used for anything other than invoking functions via its metatable.
Example
local ud = newproxy(true) -- new userdata with an empty metatable getmetatable(ud).__index = {Foo = "Bar"} -- index metamethod print(type(ud), ud.Foo) Output: userdata: 0x631fc8 Bar