[Feature request] Computed properties
まだ誰も着手していません。
評価
調査の方向性
リポジトリのファイルやテストは指定されていません。まずクラスのコンパイルパスと、issue に示されている生成された Lua メタテーブルの例を確認し、その後、getter および setter プロパティが既存のクラス動作とどのように相互作用すべきかを定義してください。示されている YueScript の例がコンパイルされ、説明されているアクセスおよび代入の結果が得られれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Some languages allow defining methods that can be used like object attributes. For example, in JavaScript:
class Foo {
get x() {
console.log("Getting x");
// In JS, member names starting wtih `#` are private and cannot
// be accessed from the outside by any means.
return this.#x;
}
set x(value) {
console.log("Setting x to", value);
this.#x = value;
}
}
I would appreciate it if YueScript could do something similar. It could look something like this:
import "yue"
class Foo
get x: () =>
print("Getting x")
@_x
set x: (value) =>
io.write("Setting x to ")
yue.p(value)
@_x = value
The output could then be something like this:
local yue = require("yue")
local Foo
local _class_0
local _base_0 = {}
local _index_0 = rawget(_base_0, "__index")
if _index_0 == nil then
_index_0 = _base_0
end
if type(_index_0) == "table" then
local _index_1 = _index_0
_index_0 = function(_, key)
return _index_1[key]
end
end
local _newindex_0 = rawget(_base_0, "__newindex")
if _newindex_0 == nil then
_newindex_0 = rawset
end
rawset(_base_0, "__index", function(self, key)
local properties = rawget(_class_0, "__properties")
local property = rawget(properties, key)
if property ~= nil then
local getter = rawget(property, "get")
if getter ~= nil then
return getter(self)
end
end
return _index_0(self, key)
end)
rawset(_base_0, "__newindex", function(self, key, value)
local properties = rawget(_class_0, "__properties")
local property = rawget(properties, key)
if property ~= nil then
local setter = rawget(property, "set")
if setter ~= nil then
return setter(self, value)
end
end
return _newindex_0(self, key, value)
end)
_class_0 = setmetatable({
__init = function() end,
__base = _base_0,
__name = "Foo",
__properties = {
x = {
get = function(self)
print("Getting x")
return self._x
end,
set = function(self, value)
io.write("Setting x to ")
yue.p(value)
self._x = value
return value
end
}
}
}, {
__index = _base_0,
__call = function(cls, ...)
local _self_0 = setmetatable({}, _base_0)
cls.__init(_self_0, ...)
return _self_0
end
})
_base_0.__class = _class_0
Foo = _class_0
return _class_0
And to test it:
print(Foo, Foo.x)
local instance = Foo()
print(instance, instance.x)
instance.x = "Test"
print(instance.x)
Its output:
table: 0x12341234 nil
Getting x
table: 0xdeadbeef nil
Setting x to "Test"
Getting x
Test
- 主要言語
- Lua
- スター
- 620
- フォーク
- 45
- 平均マージ
- 9時間 5分
- マージ済み PR(30日)
- 1
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
IppClub/YueScript のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 64/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
IppClub/YueScript の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 2 日以内に返信
-
follow-up
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
ksysoev/duet.nvim#265 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug: accuracy
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
PathOfBuildingCommunity/PathOfBuilding#10649 ·
メンテナーはふだん 1 日以内に返信
-
reMarkable
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
koreader/koreader#16485 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
nvim-orgmode/orgmode#1213 ·