44 if(this.type == "function") |
44 if(this.type == "function") |
45 return this.value; |
45 return this.value; |
46 else |
46 else |
47 throw "Attempt to call a " + this.type + " value"; |
47 throw "Attempt to call a " + this.type + " value"; |
48 }, |
48 }, |
49 index: function (key) |
49 index: function (key, raw) |
50 { |
50 { |
51 if(this.type == "table") |
51 if(this.type == "table") |
52 { |
52 { |
53 var val = this.value[key.value]; |
53 var val; |
54 if(typeof(val) == "undefined") |
54 if(key.value in this.value) |
55 return new LValue("nil", null); |
55 return this.value[key.value]; |
56 return val; |
56 else if(raw != true && this.metatable && this.metatable.type != "nil") |
|
57 { |
|
58 var __index = this.metatable.index(new LValue("string", "__index")); |
|
59 if(__index.type != "nil") |
|
60 { |
|
61 return LValueFromValue(__index.call([this, key])[0]); |
|
62 } |
|
63 } |
|
64 return new LValue("nil", null); |
57 } |
65 } |
58 else |
66 else |
59 throw "Attempt to index a " + this.type + " value"; |
67 throw "Attempt to index a " + this.type + " value"; |
60 }, |
68 }, |
61 setIndex: function (key, value) |
69 setIndex: function (key, value) |