-
Posted by weberprime on Tue, 24 Mar 2009 11:01:30
The test code:
>print(tbl.apple)
ought to be...
>print(tbl1.apple)
I actually wanted to report that the function on page 61 did not work, but I found that somewhere along the line, tbl1 had become disassociated with mt. I determined this by running: print (getmetatable(tbl1) == metatable), and the result came up false. So I ran the code: setmetatable(tbl1, mt), and reran the test code on page 62. The first test now worked properly (i.e. print(tbl1[4] now prints the error message). However the code: print(tbl.apple), printed nil ( i.e. no error message). I then chamged tbl to tbl1: print(tbl1.apple) brings up the correct error message: Attempt to access key 'apple' in {alpha, beta, gamma}.
-
Posted by weberprime on Tue, 24 Mar 2009 11:01:31
The test code:
>print(tbl.apple)
ought to be...
>print(tbl1.apple)
I actually wanted to report that the function on page 61 did not work, but I found that somewhere along the line, tbl1 had become disassociated with mt. I determined this by running: print (getmetatable(tbl1) == metatable), and the result came up false. So I ran the code: setmetatable(tbl1, mt), and reran the test code on page 62. The first test now worked properly (i.e. print(tbl1[4] now prints the error message). However the code: print(tbl.apple), printed nil ( i.e. no error message). I then chamged tbl to tbl1: print(tbl1.apple) brings up the correct error message: Attempt to access key 'apple' in {alpha, beta, gamma}.