diff options
author | Li Jin <dragon-fly@qq.com> | 2022-05-16 10:25:19 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2022-05-16 10:25:19 +0800 |
commit | de91fff7af15ae9c4a27d34b5b9266f900412a29 (patch) | |
tree | 9ececd242d326c8d5fec84043112782c95174b76 /spec/outputs | |
parent | a9fe6a5c4c17cf7e8305c1d614939ce510fb1103 (diff) | |
download | yuescript-de91fff7af15ae9c4a27d34b5b9266f900412a29.tar.gz yuescript-de91fff7af15ae9c4a27d34b5b9266f900412a29.tar.bz2 yuescript-de91fff7af15ae9c4a27d34b5b9266f900412a29.zip |
fix issue #101 by supporting metamethod syntax in class block.
Diffstat (limited to 'spec/outputs')
-rw-r--r-- | spec/outputs/class.lua | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/outputs/class.lua b/spec/outputs/class.lua index 8f7c126..9a61a67 100644 --- a/spec/outputs/class.lua +++ b/spec/outputs/class.lua | |||
@@ -1146,4 +1146,34 @@ do | |||
1146 | self.field2 = self.field1 + 1 | 1146 | self.field2 = self.field1 + 1 |
1147 | Example = _class_0 | 1147 | Example = _class_0 |
1148 | end | 1148 | end |
1149 | do | ||
1150 | local _class_0 | ||
1151 | local _base_0 = { | ||
1152 | __mul = function(self, y) | ||
1153 | return self.x * y | ||
1154 | end, | ||
1155 | ["dsd-dsd"] = 123, | ||
1156 | add = add, | ||
1157 | __add = add | ||
1158 | } | ||
1159 | if _base_0.__index == nil then | ||
1160 | _base_0.__index = _base_0 | ||
1161 | end | ||
1162 | _class_0 = setmetatable({ | ||
1163 | __init = function(self, x) | ||
1164 | self.x = x | ||
1165 | end, | ||
1166 | __base = _base_0, | ||
1167 | __name = "Foo" | ||
1168 | }, { | ||
1169 | __index = _base_0, | ||
1170 | __call = function(cls, ...) | ||
1171 | local _self_0 = setmetatable({ }, _base_0) | ||
1172 | cls.__init(_self_0, ...) | ||
1173 | return _self_0 | ||
1174 | end | ||
1175 | }) | ||
1176 | _base_0.__class = _class_0 | ||
1177 | Foo = _class_0 | ||
1178 | end | ||
1149 | return nil | 1179 | return nil |