mirror of
https://gitcode.com/JianFeeeee/LuaCangjia_api.git
synced 2026-09-20 00:48:47 +00:00
feat: 实现loadFunction预加载函数能力 + AI辅助编程标识
- 新增 loadFunction/callFunction/unloadFunction 预加载函数 API - 预加载语义:加载文件→顶层执行一次→返回函数存入Lua Registry→可多次调用 - 与管道模式(load/runScript)存储完全解耦:funcs[]+Registry vs pkgs[]+虚拟栈 - 新增错误码 5023/5024/5025 - 新增单元测试:仓颉侧 8 个 + C++ GTest 侧 11 个 - 本机以 Cangjie 1.1.0 实编译并通过功能运行验证 - README/doc 增加 AI 辅助编程标识及预加载函数模式说明
This commit is contained in:
6
test/scripts/func_add.lua
Normal file
6
test/scripts/func_add.lua
Normal file
@ -0,0 +1,6 @@
|
||||
-- func_add.lua: 顶层执行一次(计数),返回闭包函数供 callFunction 多次调用
|
||||
local callCount = 0
|
||||
return function(input)
|
||||
callCount = callCount + 1
|
||||
return "result: " .. input .. " (call #" .. callCount .. ")"
|
||||
end
|
||||
5
test/scripts/func_multi_call.lua
Normal file
5
test/scripts/func_multi_call.lua
Normal file
@ -0,0 +1,5 @@
|
||||
-- func_multi_call.lua: 顶层执行一次(初始化),返回无参闭包
|
||||
local init = "init-done"
|
||||
return function()
|
||||
return "multi:" .. init
|
||||
end
|
||||
2
test/scripts/func_not_a_function.lua
Normal file
2
test/scripts/func_not_a_function.lua
Normal file
@ -0,0 +1,2 @@
|
||||
-- func_not_a_function.lua: 顶层返回非函数,loadFunction 应报 5025
|
||||
return "not a function"
|
||||
5
test/scripts/func_runtime_error.lua
Normal file
5
test/scripts/func_runtime_error.lua
Normal file
@ -0,0 +1,5 @@
|
||||
-- func_runtime_error.lua: 返回会在运行时抛错的函数
|
||||
return function()
|
||||
local x = nil
|
||||
return x.nonexistent
|
||||
end
|
||||
Reference in New Issue
Block a user