在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1. Userdata basic"There are eight basic types in Lua: nil, boolean, number, string, userdata, function, thread, and table. The type() function gives the type name of any given value. " Ref[1]
"The userdata type allows arbitrary C data to be stored in Lua variables. It has no predefined operations in Lua, except assignment and equality test. Userdata are used to represent new types created by an application program or alibrary written in C " Ref[1] - 2.7 Userdata and Threads p18
"Lua compares tables and userdata by reference, that is, two such values are considered equal only if they are the very same object. " Ref[1] - 3.2 Relational Operations p22
2. Userdata and Metatable"Tables and userdata have individual metatables; values of other types share one single metatable for all values of that type. " Ref[1] - 13 Metatables and Metamethods p127 "The usual method to distinguish one type of userdata from other userdata is to create a unique metatable for that type. Everytime we create a userdata, we mark it with the corresponding metatable; everytime we get a userdata, we check whether it has the right metatable. " Ref[1] - 29.2 Metatables p296
3. Lua C API for userdataLua C API 中提供的针对userdata的接口有:
4. full userdata and light userdata"A light userdatum is a value that represents a C pointer (that is, a value). A light userdata is a value, not an object; we do not create them " Ref[1] 29.5 Light Userdata p301
"Light userdata are not buffers, but single pointers. They have no metatables. Like numbers, light userdata are not managed by the garbage collector. " Ref[1] 29.5 Light Userdata p302
"The real use of light userdata comes from equality. As a full userdata is an object, it is only equal to itself. A light userdata, on the other hand, represents a C pointer value. As such, it is equal to any userdata that represents the same pointer. Therefore, we can use light userdata to find C objects inside Lua. " "Another typical scenario is the need to retrieve a full userdata given its C address. " Ref[1] 29.5 Light Userdata p303
"We can not store a Lua table inside a userdatum(or inside any C structure), but Lua allows each userdata to have a user value, which can be any Lua table, associated to it." Ref[1] 30.2 An XML Parser p311
other: thread function table
Reference1. <<Programming in Lua>> 3rd Edition |
请发表评论