Cyrok
|
  |
| Joined: 11 Jan 2012 |
| Total Posts: 630 |
|
|
| 16 Jan 2012 08:04 PM |
I was working with metatables after reading Anaminus's guide to them, and I ran across this error:
local myTable = {} local myMetatable = { __newindex = function(tableName, numberKey, valueType) return "The key "..numberKey.." of the table "..tableName.." doesn't hold "..valueType.."!" end } setmetatable(myTable, myMetatable) print(myMetatable[1])
> nil
Why does it print nil? What am I doing wrong?
{ Have any broken code that needs fixing? Send me a message and maybe I can assist you. } |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2012 08:07 PM |
setmetatable(myTable, myMetatable) should be setmetatable(myMetatable,myTable)
-[::ƧѡÎḾḠΰῩ::]-[::Maker of stuff and Helper of Scripting::]- |
|
|
| Report Abuse |
|
|
Cyrok
|
  |
| Joined: 11 Jan 2012 |
| Total Posts: 630 |
|
|
| 16 Jan 2012 08:14 PM |
@swimguy777
I'm not sure if I misunderstood what you said, because I don't see how that makes sense. Doesn't setmetatable() accept two arguments, in the order of the table you metatable will control, and then the metatable itself?
{ Have any broken code that needs fixing? Send me a message and maybe I can assist you. } |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2012 08:17 PM |
O_o The wiki says I'm wrong, but I'm almost 100% positive it's worked for me like that before. Well then...
-[::ƧѡÎḾḠΰῩ::]-[::Maker of stuff and Helper of Scripting::]- |
|
|
| Report Abuse |
|
|
Cyrok
|
  |
| Joined: 11 Jan 2012 |
| Total Posts: 630 |
|
|
| 16 Jan 2012 08:23 PM |
table your* metatable will control
{ Have any broken code that needs fixing? Send me a message and maybe I can assist you. } |
|
|
| Report Abuse |
|
|