aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2022-09-08 09:26:49 +0800
committerLi Jin <dragon-fly@qq.com>2022-09-08 09:26:49 +0800
commitd4af1fa275b1d27229fc995f4a45137380040933 (patch)
tree955c76511d7021e6d1a0f06b46de3852eeac4176 /spec/outputs
parentdf85ad2e7f975026ca1e6bd84b26fff81c8d99c8 (diff)
downloadyuescript-d4af1fa275b1d27229fc995f4a45137380040933.tar.gz
yuescript-d4af1fa275b1d27229fc995f4a45137380040933.tar.bz2
yuescript-d4af1fa275b1d27229fc995f4a45137380040933.zip
redesigned metatable syntax. add support for destructuring a field with string and expression
Diffstat (limited to 'spec/outputs')
-rw-r--r--spec/outputs/destructure.lua61
-rw-r--r--spec/outputs/metatable.lua33
2 files changed, 94 insertions, 0 deletions
diff --git a/spec/outputs/destructure.lua b/spec/outputs/destructure.lua
index dfac42c..0da920e 100644
--- a/spec/outputs/destructure.lua
+++ b/spec/outputs/destructure.lua
@@ -428,3 +428,64 @@ do
428 y2, y3 = _obj_0.y2, _obj_0.y3 428 y2, y3 = _obj_0.y2, _obj_0.y3
429 end 429 end
430end 430end
431do
432 local v1, v2, v3, v4
433 do
434 local _obj_0 = tb
435 local _tmp_0, _tmp_1 = 1 + 1, self.x
436 v1, v2, v3, v4 = _obj_0[ [["abc"]]], _obj_0[_tmp_0][1], _obj_0[_tmp_0][2], _obj_0[_tmp_1]
437 if v1 == nil then
438 v1 = 111
439 end
440 if v2 == nil then
441 v2 = 222
442 end
443 if v3 == nil then
444 v3 = 333
445 end
446 if v4 == nil then
447 v4 = 444
448 end
449 end
450 local v5, v6, v7
451 do
452 local _obj_0 = tb2
453 local _tmp_2, _tmp_3 = func(), func2()
454 v5, v6, v7 = _obj_0['x-y-z'], _obj_0[_tmp_2][_tmp_3], _obj_0[_tmp_2][1]
455 end
456end
457do
458 local _obj_0 = tb
459 local value = _obj_0[name]
460 local value_meta = getmetatable(_obj_0)[name]
461end
462do
463 local tostring, add
464 do
465 local _obj_0 = getmetatable(tb)
466 tostring, add = _obj_0.__tostring, _obj_0.__add
467 if tostring == nil then
468 tostring = (function()
469 return "name"
470 end)
471 end
472 end
473 local _exp_0 = tb
474 do
475 local _tab_0 = "table" == type(_exp_0)
476 if _tab_0 then
477 local name, meta_field
478 do
479 local _obj_0 = getmetatable(_exp_0)
480 name = _obj_0.__name
481 meta_field = _obj_0["123"]
482 if name == nil then
483 name = "item"
484 end
485 end
486 if meta_field ~= nil then
487 return print(name, meta_field)
488 end
489 end
490 end
491end
diff --git a/spec/outputs/metatable.lua b/spec/outputs/metatable.lua
index 6f5ceed..937136f 100644
--- a/spec/outputs/metatable.lua
+++ b/spec/outputs/metatable.lua
@@ -111,4 +111,37 @@ do
111 ctor, update = _obj_0.new, _obj_0.update 111 ctor, update = _obj_0.new, _obj_0.update
112 end 112 end
113end 113end
114local tb = { }
115do
116 do
117 local _obj_0 = getmetatable(tb)
118 f = _obj_0["value" .. tostring(x < y)](_obj_0, 123, ...)
119 end
120 f((function(...)
121 local _obj_0 = getmetatable(tb)
122 return _obj_0['value'](_obj_0, 123, ...)
123 end)(...))
124 do
125 local _obj_0 = getmetatable(tb)
126 _obj_0[ [[ value
127 1
128 ]]](_obj_0, 123, ...)
129 end
130 local _obj_0 = getmetatable(tb)
131 return _obj_0["value" .. tostring(x > y)](_obj_0, 123, ...)
132end
133do
134 f = getmetatable(tb):__value(123, ...)
135 f(getmetatable(tb):__value(123, ...))
136 getmetatable(tb):__value(123, ...)
137 return getmetatable(tb):__value(123, ...)
138end
139do
140 f = getmetatable(tb).__value(123, ...)
141 f = getmetatable(tb)["value" .. tostring(x < y)](123, ...)
142 f(getmetatable(tb)['value'](123, ...))
143 getmetatable(tb)[ [[ value
1441]]](123, ...)
145 return getmetatable(tb)["value" .. tostring(x > y)](123, ...)
146end
114return nil 147return nil