[Feature request] Computed properties
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Không có tệp hoặc bài kiểm thử nào trong repository được nêu tên. Hãy bắt đầu bằng việc xem xét đường dẫn biên dịch class và ví dụ Lua metatable được tạo ra trong issue, sau đó xác định các thuộc tính getter và setter nên tương tác như thế nào với hành vi class hiện có. Hoàn thành khi ví dụ YueScript được hiển thị biên dịch thành công và tạo ra các kết quả truy cập và gán như mô tả.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Lua
- Star
- 620
- Fork
- 45
- Merge trung bình
- 9 giờ 5 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của IppClub/YueScript
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 64/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
-
[Feature request] Smarter macrosĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Tất cả issue của IppClub/YueScript
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 2 ngày
-
follow-up
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
ksysoev/duet.nvim#265 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug: accuracy
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
PathOfBuildingCommunity/PathOfBuilding#10649 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
reMarkable
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
koreader/koreader#16485 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
nvim-orgmode/orgmode#1213 ·