我希望能夠使用MoonScript來製作ComputerCraft的程序,但由於CC被沙箱化以防止Minecraft服務器等的安全問題,我不能要求moonscript直接並從那裏運行moonscript代碼。我必須將我的moonscript代碼轉換成lua。moonscript類的Lua輸出是MASSIVE
然而,這是有問題的,因爲moonscript的類實現是非常大的,而不是很文件化 - 保守。當我鍵入「類培根」,它輸出本作盧阿:
local Bacon
do
local _parent_0 = nil
local _base_0 = { }
_base_0.__index = _base_0
if _parent_0 then
setmetatable(_base_0, _parent_0.__base)
end
local _class_0 = setmetatable({
__init = function(self, ...)
if _parent_0 then
return _parent_0.__init(self, ...)
end
end,
__base = _base_0,
__name = "Bacon",
__parent = _parent_0
}, {
__index = function(cls, name)
local val = rawget(_base_0, name)
if val == nil and _parent_0 then
return _parent_0[name]
else
return val
end
end,
__call = function(cls, ...)
local _self_0 = setmetatable({}, _base_0)
cls.__init(_self_0, ...)
return _self_0
end
})
_base_0.__class = _class_0
if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0)
end
Bacon = _class_0
return _class_0
end
這是每類的實現,這是一種荒謬的。有什麼辦法可以在我的moonscript代碼中縮短這個嗎?
你爲什麼要擔心Lua代碼的大小?爲什麼不簡單地複製粘貼長代碼? ComputerCraft對程序大小有限制嗎? – 2013-04-30 14:07:22
這根本不是「大規模」。如果你真的擔心它,也許你可以嘗試刪除空格。和Egor說的一樣,文件大小在幾乎所有的事情上都是不相關的。 – ECrownofFire 2013-04-30 18:06:50