[Feature Request] Const Parameters

未关闭
#119 6 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
lua
领域
compilers

调研方向

首先追踪编译器如何处理函数参数以及 test/main.yue 中演示的 const 变量。比较使用 --target=5.1 和 --target=5.4 进行编译的结果,然后验证 const 参数会被接受,而对其进行赋值会被拒绝,这与现有 const 变量的行为一致。

由索引模型根据 Issue 内容生成。

描述

Since yuescript does support constvariables (for lua 5.4), I've been playing around with it for a little bit. However, one thing I noticed is that a const parameter cannot be created. I'm not sure if this a thing in lua 5.4 (I've done some Google searching, can't find it), but it would be ideal to allow const in parameters. For example:

test = (const a, b) ->
    a = 3
    return a + b

a = 1
const b = 2

print test a, b

I build this:

 ❯ yue.exe --target=5.1 test/main.yue
Built test/main.yue

It results in:

local test = (const(a, b))(function()
    local a = 3
    return a + b
end)
local a = 1
local b = 2
return print(test(a, b))

Now, even if I built it for lua 5.4, it results in the same compilation, which obviously const isn't supposed to be a valid function here, since I never defined it. I want that to mark the parameter as const so I cannot modify a, or whatever the parameter might be, in the function. I think it should be doable, honestly, because even compiling with const variables for lua 5.1 works perfectly fine, but if you were to modify the variable, yue refuses to build the source file as it should.

Even if const parameters don't exist in lua 5.4, it would be easy to add a check that the variable is marked as such in the parameter and refuse to build the file if you try to modify it, much like with a variable.

主要语言
Lua
星标
620
派生
45
平均合并
9 小时 5 分钟
30 天内合并 PR
1

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

IppClub/YueScript 的其他 Issue

查看 IppClub/YueScript 的全部 Issue

相似的 Issue

更多 Lua Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。