diff options
| -rw-r--r-- | doc/docs/de/doc/objects/object-oriented-programming.md | 22 | ||||
| -rw-r--r-- | doc/docs/doc/objects/object-oriented-programming.md | 22 | ||||
| -rw-r--r-- | doc/docs/id-id/doc/objects/object-oriented-programming.md | 22 | ||||
| -rw-r--r-- | doc/docs/pt-br/doc/objects/object-oriented-programming.md | 22 | ||||
| -rw-r--r-- | doc/docs/zh/doc/objects/object-oriented-programming.md | 22 | ||||
| -rw-r--r-- | doc/yue-de.md | 10 | ||||
| -rw-r--r-- | doc/yue-en.md | 10 | ||||
| -rw-r--r-- | doc/yue-id-id.md | 10 | ||||
| -rw-r--r-- | doc/yue-pt-br.md | 10 | ||||
| -rw-r--r-- | doc/yue-zh.md | 10 | ||||
| -rw-r--r-- | spec/inputs/whitespace.yue | 13 | ||||
| -rw-r--r-- | spec/outputs/codes_from_doc_de.lua | 58 | ||||
| -rw-r--r-- | spec/outputs/codes_from_doc_en.lua | 58 | ||||
| -rw-r--r-- | spec/outputs/codes_from_doc_id-id.lua | 58 | ||||
| -rw-r--r-- | spec/outputs/codes_from_doc_pt-br.lua | 58 | ||||
| -rw-r--r-- | spec/outputs/codes_from_doc_zh.lua | 58 | ||||
| -rw-r--r-- | spec/outputs/whitespace.lua | 5 | ||||
| -rw-r--r-- | src/yuescript/yue_compiler.cpp | 8 |
18 files changed, 475 insertions, 1 deletions
diff --git a/doc/docs/de/doc/objects/object-oriented-programming.md b/doc/docs/de/doc/objects/object-oriented-programming.md index 706cfda..705fc08 100644 --- a/doc/docs/de/doc/objects/object-oriented-programming.md +++ b/doc/docs/de/doc/objects/object-oriented-programming.md | |||
| @@ -40,6 +40,28 @@ Beachte, dass alle Methoden in der Klasse die Fat-Arrow-Syntax verwenden. Beim A | |||
| 40 | 40 | ||
| 41 | Das `@`-Präfix ist Kurzform für `self.`. `@items` wird zu `self.items`. | 41 | Das `@`-Präfix ist Kurzform für `self.`. `@items` wird zu `self.items`. |
| 42 | 42 | ||
| 43 | Der Klassenblock unterstützt auch Metatable-Felder, indem Metamethod-Schlüssel in spitzen Klammern geschrieben werden, zum Beispiel `<tostring>`. | ||
| 44 | |||
| 45 | ```yuescript | ||
| 46 | class User | ||
| 47 | new: (@name) => | ||
| 48 | <tostring>: => "User(#{@name})" | ||
| 49 | |||
| 50 | print tostring User "Yue" | ||
| 51 | ``` | ||
| 52 | |||
| 53 | <YueDisplay> | ||
| 54 | |||
| 55 | ```yue | ||
| 56 | class User | ||
| 57 | new: (@name) => | ||
| 58 | <tostring>: => "User(#{@name})" | ||
| 59 | |||
| 60 | print tostring User "Yue" | ||
| 61 | ``` | ||
| 62 | |||
| 63 | </YueDisplay> | ||
| 64 | |||
| 43 | Eine Instanz der Klasse wird erstellt, indem man den Klassennamen wie eine Funktion aufruft. | 65 | Eine Instanz der Klasse wird erstellt, indem man den Klassennamen wie eine Funktion aufruft. |
| 44 | 66 | ||
| 45 | ```yuescript | 67 | ```yuescript |
diff --git a/doc/docs/doc/objects/object-oriented-programming.md b/doc/docs/doc/objects/object-oriented-programming.md index 781ab65..b3325fa 100644 --- a/doc/docs/doc/objects/object-oriented-programming.md +++ b/doc/docs/doc/objects/object-oriented-programming.md | |||
| @@ -40,6 +40,28 @@ Notice how all the methods in the class use the fat arrow function syntax. When | |||
| 40 | 40 | ||
| 41 | The @ prefix on a variable name is shorthand for self.. @items becomes self.items. | 41 | The @ prefix on a variable name is shorthand for self.. @items becomes self.items. |
| 42 | 42 | ||
| 43 | The class block also supports metatable fields by writing metamethod keys in angle brackets, such as `<tostring>`. | ||
| 44 | |||
| 45 | ```yuescript | ||
| 46 | class User | ||
| 47 | new: (@name) => | ||
| 48 | <tostring>: => "User(#{@name})" | ||
| 49 | |||
| 50 | print tostring User "Yue" | ||
| 51 | ``` | ||
| 52 | |||
| 53 | <YueDisplay> | ||
| 54 | |||
| 55 | ```yue | ||
| 56 | class User | ||
| 57 | new: (@name) => | ||
| 58 | <tostring>: => "User(#{@name})" | ||
| 59 | |||
| 60 | print tostring User "Yue" | ||
| 61 | ``` | ||
| 62 | |||
| 63 | </YueDisplay> | ||
| 64 | |||
| 43 | Creating an instance of the class is done by calling the name of the class as a function. | 65 | Creating an instance of the class is done by calling the name of the class as a function. |
| 44 | 66 | ||
| 45 | ```yuescript | 67 | ```yuescript |
diff --git a/doc/docs/id-id/doc/objects/object-oriented-programming.md b/doc/docs/id-id/doc/objects/object-oriented-programming.md index 7d5d420..cc74690 100644 --- a/doc/docs/id-id/doc/objects/object-oriented-programming.md +++ b/doc/docs/id-id/doc/objects/object-oriented-programming.md | |||
| @@ -40,6 +40,28 @@ Perhatikan bahwa semua method di kelas menggunakan sintaks fungsi panah tebal. S | |||
| 40 | 40 | ||
| 41 | Prefiks `@` pada nama variabel adalah singkatan untuk `self.`. `@items` menjadi `self.items`. | 41 | Prefiks `@` pada nama variabel adalah singkatan untuk `self.`. `@items` menjadi `self.items`. |
| 42 | 42 | ||
| 43 | Blok kelas juga mendukung field metatable dengan menulis key metamethod dalam tanda kurung sudut, misalnya `<tostring>`. | ||
| 44 | |||
| 45 | ```yuescript | ||
| 46 | class User | ||
| 47 | new: (@name) => | ||
| 48 | <tostring>: => "User(#{@name})" | ||
| 49 | |||
| 50 | print tostring User "Yue" | ||
| 51 | ``` | ||
| 52 | |||
| 53 | <YueDisplay> | ||
| 54 | |||
| 55 | ```yue | ||
| 56 | class User | ||
| 57 | new: (@name) => | ||
| 58 | <tostring>: => "User(#{@name})" | ||
| 59 | |||
| 60 | print tostring User "Yue" | ||
| 61 | ``` | ||
| 62 | |||
| 63 | </YueDisplay> | ||
| 64 | |||
| 43 | Membuat instance kelas dilakukan dengan memanggil nama kelas sebagai fungsi. | 65 | Membuat instance kelas dilakukan dengan memanggil nama kelas sebagai fungsi. |
| 44 | 66 | ||
| 45 | ```yuescript | 67 | ```yuescript |
diff --git a/doc/docs/pt-br/doc/objects/object-oriented-programming.md b/doc/docs/pt-br/doc/objects/object-oriented-programming.md index 54a559a..01aeff3 100644 --- a/doc/docs/pt-br/doc/objects/object-oriented-programming.md +++ b/doc/docs/pt-br/doc/objects/object-oriented-programming.md | |||
| @@ -40,6 +40,28 @@ Observe como todos os métodos da classe usam a sintaxe de função seta fat. Ao | |||
| 40 | 40 | ||
| 41 | O prefixo @ em um nome de variável é abreviação para self.. @items torna-se self.items. | 41 | O prefixo @ em um nome de variável é abreviação para self.. @items torna-se self.items. |
| 42 | 42 | ||
| 43 | O bloco da classe também suporta campos de metatable escrevendo chaves de metamétodo entre `<>`, como `<tostring>`. | ||
| 44 | |||
| 45 | ```yuescript | ||
| 46 | class User | ||
| 47 | new: (@name) => | ||
| 48 | <tostring>: => "User(#{@name})" | ||
| 49 | |||
| 50 | print tostring User "Yue" | ||
| 51 | ``` | ||
| 52 | |||
| 53 | <YueDisplay> | ||
| 54 | |||
| 55 | ```yue | ||
| 56 | class User | ||
| 57 | new: (@name) => | ||
| 58 | <tostring>: => "User(#{@name})" | ||
| 59 | |||
| 60 | print tostring User "Yue" | ||
| 61 | ``` | ||
| 62 | |||
| 63 | </YueDisplay> | ||
| 64 | |||
| 43 | Criar uma instância da classe é feito chamando o nome da classe como uma função. | 65 | Criar uma instância da classe é feito chamando o nome da classe como uma função. |
| 44 | 66 | ||
| 45 | ```yuescript | 67 | ```yuescript |
diff --git a/doc/docs/zh/doc/objects/object-oriented-programming.md b/doc/docs/zh/doc/objects/object-oriented-programming.md index 04f816a..270c2b3 100644 --- a/doc/docs/zh/doc/objects/object-oriented-programming.md +++ b/doc/docs/zh/doc/objects/object-oriented-programming.md | |||
| @@ -38,6 +38,28 @@ class Inventory | |||
| 38 | 38 | ||
| 39 |   此外,“@” 前缀在变量名上起到了简化作用,代表 “self”。例如,`@items` 就等同于 `self.items`。 | 39 |   此外,“@” 前缀在变量名上起到了简化作用,代表 “self”。例如,`@items` 就等同于 `self.items`。 |
| 40 | 40 | ||
| 41 |   类定义块中也支持通过尖括号写元方法字段,例如 `<tostring>`。 | ||
| 42 | |||
| 43 | ```yuescript | ||
| 44 | class User | ||
| 45 | new: (@name) => | ||
| 46 | <tostring>: => "User(#{@name})" | ||
| 47 | |||
| 48 | print tostring User "Yue" | ||
| 49 | ``` | ||
| 50 | |||
| 51 | <YueDisplay> | ||
| 52 | |||
| 53 | ```yue | ||
| 54 | class User | ||
| 55 | new: (@name) => | ||
| 56 | <tostring>: => "User(#{@name})" | ||
| 57 | |||
| 58 | print tostring User "Yue" | ||
| 59 | ``` | ||
| 60 | |||
| 61 | </YueDisplay> | ||
| 62 | |||
| 41 |   为了创建类的一个新实例,可以将类名当作一个函数来调用,这样就可以生成并返回一个新的实例。 | 63 |   为了创建类的一个新实例,可以将类名当作一个函数来调用,这样就可以生成并返回一个新的实例。 |
| 42 | 64 | ||
| 43 | ```yuescript | 65 | ```yuescript |
diff --git a/doc/yue-de.md b/doc/yue-de.md index f0979e0..97063f4 100644 --- a/doc/yue-de.md +++ b/doc/yue-de.md | |||
| @@ -508,6 +508,16 @@ Beachte, dass alle Methoden in der Klasse die Fat-Arrow-Syntax verwenden. Beim A | |||
| 508 | 508 | ||
| 509 | Das `@`-Präfix ist Kurzform für `self.`. `@items` wird zu `self.items`. | 509 | Das `@`-Präfix ist Kurzform für `self.`. `@items` wird zu `self.items`. |
| 510 | 510 | ||
| 511 | Der Klassenblock unterstützt auch Metatable-Felder, indem Metamethod-Schlüssel in spitzen Klammern geschrieben werden, zum Beispiel `<tostring>`. | ||
| 512 | |||
| 513 | ```yuescript | ||
| 514 | class User | ||
| 515 | new: (@name) => | ||
| 516 | <tostring>: => "User(#{@name})" | ||
| 517 | |||
| 518 | print tostring User "Yue" | ||
| 519 | ``` | ||
| 520 | |||
| 511 | Eine Instanz der Klasse wird erstellt, indem man den Klassennamen wie eine Funktion aufruft. | 521 | Eine Instanz der Klasse wird erstellt, indem man den Klassennamen wie eine Funktion aufruft. |
| 512 | 522 | ||
| 513 | ```yuescript | 523 | ```yuescript |
diff --git a/doc/yue-en.md b/doc/yue-en.md index 6680281..8f8370d 100644 --- a/doc/yue-en.md +++ b/doc/yue-en.md | |||
| @@ -508,6 +508,16 @@ Notice how all the methods in the class use the fat arrow function syntax. When | |||
| 508 | 508 | ||
| 509 | The @ prefix on a variable name is shorthand for self.. @items becomes self.items. | 509 | The @ prefix on a variable name is shorthand for self.. @items becomes self.items. |
| 510 | 510 | ||
| 511 | The class block also supports metatable fields by writing metamethod keys in angle brackets, such as `<tostring>`. | ||
| 512 | |||
| 513 | ```yuescript | ||
| 514 | class User | ||
| 515 | new: (@name) => | ||
| 516 | <tostring>: => "User(#{@name})" | ||
| 517 | |||
| 518 | print tostring User "Yue" | ||
| 519 | ``` | ||
| 520 | |||
| 511 | Creating an instance of the class is done by calling the name of the class as a function. | 521 | Creating an instance of the class is done by calling the name of the class as a function. |
| 512 | 522 | ||
| 513 | ```yuescript | 523 | ```yuescript |
diff --git a/doc/yue-id-id.md b/doc/yue-id-id.md index 863e187..39ba24d 100644 --- a/doc/yue-id-id.md +++ b/doc/yue-id-id.md | |||
| @@ -508,6 +508,16 @@ Perhatikan bahwa semua method di kelas menggunakan sintaks fungsi panah tebal. S | |||
| 508 | 508 | ||
| 509 | Prefiks `@` pada nama variabel adalah singkatan untuk `self.`. `@items` menjadi `self.items`. | 509 | Prefiks `@` pada nama variabel adalah singkatan untuk `self.`. `@items` menjadi `self.items`. |
| 510 | 510 | ||
| 511 | Blok kelas juga mendukung field metatable dengan menulis key metamethod dalam tanda kurung sudut, misalnya `<tostring>`. | ||
| 512 | |||
| 513 | ```yuescript | ||
| 514 | class User | ||
| 515 | new: (@name) => | ||
| 516 | <tostring>: => "User(#{@name})" | ||
| 517 | |||
| 518 | print tostring User "Yue" | ||
| 519 | ``` | ||
| 520 | |||
| 511 | Membuat instance kelas dilakukan dengan memanggil nama kelas sebagai fungsi. | 521 | Membuat instance kelas dilakukan dengan memanggil nama kelas sebagai fungsi. |
| 512 | 522 | ||
| 513 | ```yuescript | 523 | ```yuescript |
diff --git a/doc/yue-pt-br.md b/doc/yue-pt-br.md index a1408c2..a0e3268 100644 --- a/doc/yue-pt-br.md +++ b/doc/yue-pt-br.md | |||
| @@ -508,6 +508,16 @@ Observe como todos os métodos da classe usam a sintaxe de função seta fat. Ao | |||
| 508 | 508 | ||
| 509 | O prefixo @ em um nome de variável é abreviação para self.. @items torna-se self.items. | 509 | O prefixo @ em um nome de variável é abreviação para self.. @items torna-se self.items. |
| 510 | 510 | ||
| 511 | O bloco da classe também suporta campos de metatable escrevendo chaves de metamétodo entre `<>`, como `<tostring>`. | ||
| 512 | |||
| 513 | ```yuescript | ||
| 514 | class User | ||
| 515 | new: (@name) => | ||
| 516 | <tostring>: => "User(#{@name})" | ||
| 517 | |||
| 518 | print tostring User "Yue" | ||
| 519 | ``` | ||
| 520 | |||
| 511 | Criar uma instância da classe é feito chamando o nome da classe como uma função. | 521 | Criar uma instância da classe é feito chamando o nome da classe como uma função. |
| 512 | 522 | ||
| 513 | ```yuescript | 523 | ```yuescript |
diff --git a/doc/yue-zh.md b/doc/yue-zh.md index ac7e4b2..cb44d22 100644 --- a/doc/yue-zh.md +++ b/doc/yue-zh.md | |||
| @@ -506,6 +506,16 @@ class Inventory | |||
| 506 | 506 | ||
| 507 |   此外,“@” 前缀在变量名上起到了简化作用,代表 “self”。例如,`@items` 就等同于 `self.items`。 | 507 |   此外,“@” 前缀在变量名上起到了简化作用,代表 “self”。例如,`@items` 就等同于 `self.items`。 |
| 508 | 508 | ||
| 509 |   类定义块中也支持通过尖括号写元方法字段,例如 `<tostring>`。 | ||
| 510 | |||
| 511 | ```yuescript | ||
| 512 | class User | ||
| 513 | new: (@name) => | ||
| 514 | <tostring>: => "User(#{@name})" | ||
| 515 | |||
| 516 | print tostring User "Yue" | ||
| 517 | ``` | ||
| 518 | |||
| 509 |   为了创建类的一个新实例,可以将类名当作一个函数来调用,这样就可以生成并返回一个新的实例。 | 519 |   为了创建类的一个新实例,可以将类名当作一个函数来调用,这样就可以生成并返回一个新的实例。 |
| 510 | 520 | ||
| 511 | ```yuescript | 521 | ```yuescript |
diff --git a/spec/inputs/whitespace.yue b/spec/inputs/whitespace.yue index d0acdde..18e1628 100644 --- a/spec/inputs/whitespace.yue +++ b/spec/inputs/whitespace.yue | |||
| @@ -246,4 +246,17 @@ do | |||
| 246 | -- init xd | 246 | -- init xd |
| 247 | close xd = <close>: => | 247 | close xd = <close>: => |
| 248 | 248 | ||
| 249 | |||
| 250 | do | ||
| 251 | { | ||
| 252 | numbers: [ | ||
| 253 | first | ||
| 254 | second | ||
| 255 | ] | ||
| 256 | properties: | ||
| 257 | :color | ||
| 258 | |||
| 259 | -- dsd | ||
| 260 | } = obj2 | ||
| 261 | |||
| 249 | nil | 262 | nil |
diff --git a/spec/outputs/codes_from_doc_de.lua b/spec/outputs/codes_from_doc_de.lua index d8115ee..28ed4e7 100644 --- a/spec/outputs/codes_from_doc_de.lua +++ b/spec/outputs/codes_from_doc_de.lua | |||
| @@ -939,6 +939,35 @@ _class_0 = setmetatable({ | |||
| 939 | }) | 939 | }) |
| 940 | _base_0.__class = _class_0 | 940 | _base_0.__class = _class_0 |
| 941 | Inventory = _class_0 | 941 | Inventory = _class_0 |
| 942 | local User | ||
| 943 | do | ||
| 944 | local _class_0 | ||
| 945 | local _base_0 = { | ||
| 946 | __tostring = function(self) | ||
| 947 | return "User(" .. tostring(self.name) .. ")" | ||
| 948 | end | ||
| 949 | } | ||
| 950 | if _base_0.__index == nil then | ||
| 951 | _base_0.__index = _base_0 | ||
| 952 | end | ||
| 953 | _class_0 = setmetatable({ | ||
| 954 | __init = function(self, name) | ||
| 955 | self.name = name | ||
| 956 | end, | ||
| 957 | __base = _base_0, | ||
| 958 | __name = "User" | ||
| 959 | }, { | ||
| 960 | __index = _base_0, | ||
| 961 | __call = function(cls, ...) | ||
| 962 | local _self_0 = setmetatable({ }, _base_0) | ||
| 963 | cls.__init(_self_0, ...) | ||
| 964 | return _self_0 | ||
| 965 | end | ||
| 966 | }) | ||
| 967 | _base_0.__class = _class_0 | ||
| 968 | User = _class_0 | ||
| 969 | end | ||
| 970 | print(tostring(User("Yue"))) | ||
| 942 | local inv = Inventory() | 971 | local inv = Inventory() |
| 943 | inv:add_item("T-Shirt") | 972 | inv:add_item("T-Shirt") |
| 944 | inv:add_item("Hose") | 973 | inv:add_item("Hose") |
| @@ -1559,6 +1588,35 @@ _class_0 = setmetatable({ | |||
| 1559 | }) | 1588 | }) |
| 1560 | _base_0.__class = _class_0 | 1589 | _base_0.__class = _class_0 |
| 1561 | Inventory = _class_0 | 1590 | Inventory = _class_0 |
| 1591 | local User | ||
| 1592 | do | ||
| 1593 | local _class_0 | ||
| 1594 | local _base_0 = { | ||
| 1595 | __tostring = function(self) | ||
| 1596 | return "User(" .. tostring(self.name) .. ")" | ||
| 1597 | end | ||
| 1598 | } | ||
| 1599 | if _base_0.__index == nil then | ||
| 1600 | _base_0.__index = _base_0 | ||
| 1601 | end | ||
| 1602 | _class_0 = setmetatable({ | ||
| 1603 | __init = function(self, name) | ||
| 1604 | self.name = name | ||
| 1605 | end, | ||
| 1606 | __base = _base_0, | ||
| 1607 | __name = "User" | ||
| 1608 | }, { | ||
| 1609 | __index = _base_0, | ||
| 1610 | __call = function(cls, ...) | ||
| 1611 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1612 | cls.__init(_self_0, ...) | ||
| 1613 | return _self_0 | ||
| 1614 | end | ||
| 1615 | }) | ||
| 1616 | _base_0.__class = _class_0 | ||
| 1617 | User = _class_0 | ||
| 1618 | end | ||
| 1619 | print(tostring(User("Yue"))) | ||
| 1562 | local inv = Inventory() | 1620 | local inv = Inventory() |
| 1563 | inv:add_item("T-Shirt") | 1621 | inv:add_item("T-Shirt") |
| 1564 | inv:add_item("Hose") | 1622 | inv:add_item("Hose") |
diff --git a/spec/outputs/codes_from_doc_en.lua b/spec/outputs/codes_from_doc_en.lua index 66fb0b7..1fdc56d 100644 --- a/spec/outputs/codes_from_doc_en.lua +++ b/spec/outputs/codes_from_doc_en.lua | |||
| @@ -939,6 +939,35 @@ _class_0 = setmetatable({ | |||
| 939 | }) | 939 | }) |
| 940 | _base_0.__class = _class_0 | 940 | _base_0.__class = _class_0 |
| 941 | Inventory = _class_0 | 941 | Inventory = _class_0 |
| 942 | local User | ||
| 943 | do | ||
| 944 | local _class_0 | ||
| 945 | local _base_0 = { | ||
| 946 | __tostring = function(self) | ||
| 947 | return "User(" .. tostring(self.name) .. ")" | ||
| 948 | end | ||
| 949 | } | ||
| 950 | if _base_0.__index == nil then | ||
| 951 | _base_0.__index = _base_0 | ||
| 952 | end | ||
| 953 | _class_0 = setmetatable({ | ||
| 954 | __init = function(self, name) | ||
| 955 | self.name = name | ||
| 956 | end, | ||
| 957 | __base = _base_0, | ||
| 958 | __name = "User" | ||
| 959 | }, { | ||
| 960 | __index = _base_0, | ||
| 961 | __call = function(cls, ...) | ||
| 962 | local _self_0 = setmetatable({ }, _base_0) | ||
| 963 | cls.__init(_self_0, ...) | ||
| 964 | return _self_0 | ||
| 965 | end | ||
| 966 | }) | ||
| 967 | _base_0.__class = _class_0 | ||
| 968 | User = _class_0 | ||
| 969 | end | ||
| 970 | print(tostring(User("Yue"))) | ||
| 942 | local inv = Inventory() | 971 | local inv = Inventory() |
| 943 | inv:add_item("t-shirt") | 972 | inv:add_item("t-shirt") |
| 944 | inv:add_item("pants") | 973 | inv:add_item("pants") |
| @@ -1559,6 +1588,35 @@ _class_0 = setmetatable({ | |||
| 1559 | }) | 1588 | }) |
| 1560 | _base_0.__class = _class_0 | 1589 | _base_0.__class = _class_0 |
| 1561 | Inventory = _class_0 | 1590 | Inventory = _class_0 |
| 1591 | local User | ||
| 1592 | do | ||
| 1593 | local _class_0 | ||
| 1594 | local _base_0 = { | ||
| 1595 | __tostring = function(self) | ||
| 1596 | return "User(" .. tostring(self.name) .. ")" | ||
| 1597 | end | ||
| 1598 | } | ||
| 1599 | if _base_0.__index == nil then | ||
| 1600 | _base_0.__index = _base_0 | ||
| 1601 | end | ||
| 1602 | _class_0 = setmetatable({ | ||
| 1603 | __init = function(self, name) | ||
| 1604 | self.name = name | ||
| 1605 | end, | ||
| 1606 | __base = _base_0, | ||
| 1607 | __name = "User" | ||
| 1608 | }, { | ||
| 1609 | __index = _base_0, | ||
| 1610 | __call = function(cls, ...) | ||
| 1611 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1612 | cls.__init(_self_0, ...) | ||
| 1613 | return _self_0 | ||
| 1614 | end | ||
| 1615 | }) | ||
| 1616 | _base_0.__class = _class_0 | ||
| 1617 | User = _class_0 | ||
| 1618 | end | ||
| 1619 | print(tostring(User("Yue"))) | ||
| 1562 | local inv = Inventory() | 1620 | local inv = Inventory() |
| 1563 | inv:add_item("t-shirt") | 1621 | inv:add_item("t-shirt") |
| 1564 | inv:add_item("pants") | 1622 | inv:add_item("pants") |
diff --git a/spec/outputs/codes_from_doc_id-id.lua b/spec/outputs/codes_from_doc_id-id.lua index 6caf79c..2201dee 100644 --- a/spec/outputs/codes_from_doc_id-id.lua +++ b/spec/outputs/codes_from_doc_id-id.lua | |||
| @@ -939,6 +939,35 @@ _class_0 = setmetatable({ | |||
| 939 | }) | 939 | }) |
| 940 | _base_0.__class = _class_0 | 940 | _base_0.__class = _class_0 |
| 941 | Inventory = _class_0 | 941 | Inventory = _class_0 |
| 942 | local User | ||
| 943 | do | ||
| 944 | local _class_0 | ||
| 945 | local _base_0 = { | ||
| 946 | __tostring = function(self) | ||
| 947 | return "User(" .. tostring(self.name) .. ")" | ||
| 948 | end | ||
| 949 | } | ||
| 950 | if _base_0.__index == nil then | ||
| 951 | _base_0.__index = _base_0 | ||
| 952 | end | ||
| 953 | _class_0 = setmetatable({ | ||
| 954 | __init = function(self, name) | ||
| 955 | self.name = name | ||
| 956 | end, | ||
| 957 | __base = _base_0, | ||
| 958 | __name = "User" | ||
| 959 | }, { | ||
| 960 | __index = _base_0, | ||
| 961 | __call = function(cls, ...) | ||
| 962 | local _self_0 = setmetatable({ }, _base_0) | ||
| 963 | cls.__init(_self_0, ...) | ||
| 964 | return _self_0 | ||
| 965 | end | ||
| 966 | }) | ||
| 967 | _base_0.__class = _class_0 | ||
| 968 | User = _class_0 | ||
| 969 | end | ||
| 970 | print(tostring(User("Yue"))) | ||
| 942 | local inv = Inventory() | 971 | local inv = Inventory() |
| 943 | inv:add_item("t-shirt") | 972 | inv:add_item("t-shirt") |
| 944 | inv:add_item("pants") | 973 | inv:add_item("pants") |
| @@ -1559,6 +1588,35 @@ _class_0 = setmetatable({ | |||
| 1559 | }) | 1588 | }) |
| 1560 | _base_0.__class = _class_0 | 1589 | _base_0.__class = _class_0 |
| 1561 | Inventory = _class_0 | 1590 | Inventory = _class_0 |
| 1591 | local User | ||
| 1592 | do | ||
| 1593 | local _class_0 | ||
| 1594 | local _base_0 = { | ||
| 1595 | __tostring = function(self) | ||
| 1596 | return "User(" .. tostring(self.name) .. ")" | ||
| 1597 | end | ||
| 1598 | } | ||
| 1599 | if _base_0.__index == nil then | ||
| 1600 | _base_0.__index = _base_0 | ||
| 1601 | end | ||
| 1602 | _class_0 = setmetatable({ | ||
| 1603 | __init = function(self, name) | ||
| 1604 | self.name = name | ||
| 1605 | end, | ||
| 1606 | __base = _base_0, | ||
| 1607 | __name = "User" | ||
| 1608 | }, { | ||
| 1609 | __index = _base_0, | ||
| 1610 | __call = function(cls, ...) | ||
| 1611 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1612 | cls.__init(_self_0, ...) | ||
| 1613 | return _self_0 | ||
| 1614 | end | ||
| 1615 | }) | ||
| 1616 | _base_0.__class = _class_0 | ||
| 1617 | User = _class_0 | ||
| 1618 | end | ||
| 1619 | print(tostring(User("Yue"))) | ||
| 1562 | local inv = Inventory() | 1620 | local inv = Inventory() |
| 1563 | inv:add_item("t-shirt") | 1621 | inv:add_item("t-shirt") |
| 1564 | inv:add_item("pants") | 1622 | inv:add_item("pants") |
diff --git a/spec/outputs/codes_from_doc_pt-br.lua b/spec/outputs/codes_from_doc_pt-br.lua index 22f9bb9..b3bf0b3 100644 --- a/spec/outputs/codes_from_doc_pt-br.lua +++ b/spec/outputs/codes_from_doc_pt-br.lua | |||
| @@ -939,6 +939,35 @@ _class_0 = setmetatable({ | |||
| 939 | }) | 939 | }) |
| 940 | _base_0.__class = _class_0 | 940 | _base_0.__class = _class_0 |
| 941 | Inventory = _class_0 | 941 | Inventory = _class_0 |
| 942 | local User | ||
| 943 | do | ||
| 944 | local _class_0 | ||
| 945 | local _base_0 = { | ||
| 946 | __tostring = function(self) | ||
| 947 | return "User(" .. tostring(self.name) .. ")" | ||
| 948 | end | ||
| 949 | } | ||
| 950 | if _base_0.__index == nil then | ||
| 951 | _base_0.__index = _base_0 | ||
| 952 | end | ||
| 953 | _class_0 = setmetatable({ | ||
| 954 | __init = function(self, name) | ||
| 955 | self.name = name | ||
| 956 | end, | ||
| 957 | __base = _base_0, | ||
| 958 | __name = "User" | ||
| 959 | }, { | ||
| 960 | __index = _base_0, | ||
| 961 | __call = function(cls, ...) | ||
| 962 | local _self_0 = setmetatable({ }, _base_0) | ||
| 963 | cls.__init(_self_0, ...) | ||
| 964 | return _self_0 | ||
| 965 | end | ||
| 966 | }) | ||
| 967 | _base_0.__class = _class_0 | ||
| 968 | User = _class_0 | ||
| 969 | end | ||
| 970 | print(tostring(User("Yue"))) | ||
| 942 | local inv = Inventory() | 971 | local inv = Inventory() |
| 943 | inv:add_item("t-shirt") | 972 | inv:add_item("t-shirt") |
| 944 | inv:add_item("pants") | 973 | inv:add_item("pants") |
| @@ -1559,6 +1588,35 @@ _class_0 = setmetatable({ | |||
| 1559 | }) | 1588 | }) |
| 1560 | _base_0.__class = _class_0 | 1589 | _base_0.__class = _class_0 |
| 1561 | Inventory = _class_0 | 1590 | Inventory = _class_0 |
| 1591 | local User | ||
| 1592 | do | ||
| 1593 | local _class_0 | ||
| 1594 | local _base_0 = { | ||
| 1595 | __tostring = function(self) | ||
| 1596 | return "User(" .. tostring(self.name) .. ")" | ||
| 1597 | end | ||
| 1598 | } | ||
| 1599 | if _base_0.__index == nil then | ||
| 1600 | _base_0.__index = _base_0 | ||
| 1601 | end | ||
| 1602 | _class_0 = setmetatable({ | ||
| 1603 | __init = function(self, name) | ||
| 1604 | self.name = name | ||
| 1605 | end, | ||
| 1606 | __base = _base_0, | ||
| 1607 | __name = "User" | ||
| 1608 | }, { | ||
| 1609 | __index = _base_0, | ||
| 1610 | __call = function(cls, ...) | ||
| 1611 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1612 | cls.__init(_self_0, ...) | ||
| 1613 | return _self_0 | ||
| 1614 | end | ||
| 1615 | }) | ||
| 1616 | _base_0.__class = _class_0 | ||
| 1617 | User = _class_0 | ||
| 1618 | end | ||
| 1619 | print(tostring(User("Yue"))) | ||
| 1562 | local inv = Inventory() | 1620 | local inv = Inventory() |
| 1563 | inv:add_item("t-shirt") | 1621 | inv:add_item("t-shirt") |
| 1564 | inv:add_item("pants") | 1622 | inv:add_item("pants") |
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua index cf08375..5756793 100644 --- a/spec/outputs/codes_from_doc_zh.lua +++ b/spec/outputs/codes_from_doc_zh.lua | |||
| @@ -939,6 +939,35 @@ _class_0 = setmetatable({ | |||
| 939 | }) | 939 | }) |
| 940 | _base_0.__class = _class_0 | 940 | _base_0.__class = _class_0 |
| 941 | Inventory = _class_0 | 941 | Inventory = _class_0 |
| 942 | local User | ||
| 943 | do | ||
| 944 | local _class_0 | ||
| 945 | local _base_0 = { | ||
| 946 | __tostring = function(self) | ||
| 947 | return "User(" .. tostring(self.name) .. ")" | ||
| 948 | end | ||
| 949 | } | ||
| 950 | if _base_0.__index == nil then | ||
| 951 | _base_0.__index = _base_0 | ||
| 952 | end | ||
| 953 | _class_0 = setmetatable({ | ||
| 954 | __init = function(self, name) | ||
| 955 | self.name = name | ||
| 956 | end, | ||
| 957 | __base = _base_0, | ||
| 958 | __name = "User" | ||
| 959 | }, { | ||
| 960 | __index = _base_0, | ||
| 961 | __call = function(cls, ...) | ||
| 962 | local _self_0 = setmetatable({ }, _base_0) | ||
| 963 | cls.__init(_self_0, ...) | ||
| 964 | return _self_0 | ||
| 965 | end | ||
| 966 | }) | ||
| 967 | _base_0.__class = _class_0 | ||
| 968 | User = _class_0 | ||
| 969 | end | ||
| 970 | print(tostring(User("Yue"))) | ||
| 942 | local inv = Inventory() | 971 | local inv = Inventory() |
| 943 | inv:add_item("t-shirt") | 972 | inv:add_item("t-shirt") |
| 944 | inv:add_item("pants") | 973 | inv:add_item("pants") |
| @@ -1559,6 +1588,35 @@ _class_0 = setmetatable({ | |||
| 1559 | }) | 1588 | }) |
| 1560 | _base_0.__class = _class_0 | 1589 | _base_0.__class = _class_0 |
| 1561 | Inventory = _class_0 | 1590 | Inventory = _class_0 |
| 1591 | local User | ||
| 1592 | do | ||
| 1593 | local _class_0 | ||
| 1594 | local _base_0 = { | ||
| 1595 | __tostring = function(self) | ||
| 1596 | return "User(" .. tostring(self.name) .. ")" | ||
| 1597 | end | ||
| 1598 | } | ||
| 1599 | if _base_0.__index == nil then | ||
| 1600 | _base_0.__index = _base_0 | ||
| 1601 | end | ||
| 1602 | _class_0 = setmetatable({ | ||
| 1603 | __init = function(self, name) | ||
| 1604 | self.name = name | ||
| 1605 | end, | ||
| 1606 | __base = _base_0, | ||
| 1607 | __name = "User" | ||
| 1608 | }, { | ||
| 1609 | __index = _base_0, | ||
| 1610 | __call = function(cls, ...) | ||
| 1611 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1612 | cls.__init(_self_0, ...) | ||
| 1613 | return _self_0 | ||
| 1614 | end | ||
| 1615 | }) | ||
| 1616 | _base_0.__class = _class_0 | ||
| 1617 | User = _class_0 | ||
| 1618 | end | ||
| 1619 | print(tostring(User("Yue"))) | ||
| 1562 | local inv = Inventory() | 1620 | local inv = Inventory() |
| 1563 | inv:add_item("t-shirt") | 1621 | inv:add_item("t-shirt") |
| 1564 | inv:add_item("pants") | 1622 | inv:add_item("pants") |
diff --git a/spec/outputs/whitespace.lua b/spec/outputs/whitespace.lua index a0d225f..768f2ac 100644 --- a/spec/outputs/whitespace.lua +++ b/spec/outputs/whitespace.lua | |||
| @@ -183,4 +183,9 @@ do | |||
| 183 | local _close_0 <close> = xd | 183 | local _close_0 <close> = xd |
| 184 | CY = _class_0 | 184 | CY = _class_0 |
| 185 | end | 185 | end |
| 186 | do | ||
| 187 | local first, second, color | ||
| 188 | local _obj_0 = obj2 | ||
| 189 | first, second, color = _obj_0.numbers[1], _obj_0.numbers[2], _obj_0.properties.color | ||
| 190 | end | ||
| 186 | return nil | 191 | return nil |
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 10fd5d6..514b6f2 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
| @@ -78,7 +78,7 @@ static std::unordered_set<std::string> Metamethods = { | |||
| 78 | "close"s // Lua 5.4 | 78 | "close"s // Lua 5.4 |
| 79 | }; | 79 | }; |
| 80 | 80 | ||
| 81 | const std::string_view version = "0.33.6"sv; | 81 | const std::string_view version = "0.33.7"sv; |
| 82 | const std::string_view extension = "yue"sv; | 82 | const std::string_view extension = "yue"sv; |
| 83 | 83 | ||
| 84 | class CompileError : public std::logic_error { | 84 | class CompileError : public std::logic_error { |
| @@ -3028,6 +3028,9 @@ private: | |||
| 3028 | auto subMetaDestruct = node->new_ptr<TableLit_t>(); | 3028 | auto subMetaDestruct = node->new_ptr<TableLit_t>(); |
| 3029 | for (auto pair : *tableItems) { | 3029 | for (auto pair : *tableItems) { |
| 3030 | switch (pair->get_id()) { | 3030 | switch (pair->get_id()) { |
| 3031 | case id<YueComment_t>(): | ||
| 3032 | case id<EmptyLine_t>(): | ||
| 3033 | break; | ||
| 3031 | case id<Exp_t>(): | 3034 | case id<Exp_t>(): |
| 3032 | case id<NormalDef_t>(): { | 3035 | case id<NormalDef_t>(): { |
| 3033 | ++index; | 3036 | ++index; |
| @@ -3429,6 +3432,9 @@ private: | |||
| 3429 | } | 3432 | } |
| 3430 | for (auto item : *dlist) { | 3433 | for (auto item : *dlist) { |
| 3431 | switch (item->get_id()) { | 3434 | switch (item->get_id()) { |
| 3435 | case id<YueComment_t>(): | ||
| 3436 | case id<EmptyLine_t>(): | ||
| 3437 | break; | ||
| 3432 | case id<MetaVariablePairDef_t>(): { | 3438 | case id<MetaVariablePairDef_t>(): { |
| 3433 | auto mvp = static_cast<MetaVariablePairDef_t*>(item); | 3439 | auto mvp = static_cast<MetaVariablePairDef_t*>(item); |
| 3434 | auto mp = mvp->pair.get(); | 3440 | auto mp = mvp->pair.get(); |
