feat: typed interop 原始类型直通映射 (Int64/Float64/Bool)

- C++ 层: callfunction_int/num/bool/void + run_int/num/bool/void
- 新增 capture_result()/finish_call() 正确计算 lua_pcall 实际返回值数量,
  修复无返回值场景下误读栈残留的问题
- C FFI 层: 11 个新导出函数 + lua_runner 结构体 tresult_* 镜像字段
- 仓颉层: callFunctionInt/Num/Bool, runScriptInt/Num/Bool, resultType()
  带严格类型校验(不匹配抛 LUAERR_RESULT_TYPE)
- 大整数跨 2^53 保真(字符串路径做不到)
- 管道模式语义保留给字符串 API; typed run_* 为独立调用保持栈清洁
- GTest 新增 10 个 typed 测试用例(共 44 个全部通过)
- 独立程序验证仓颉层运行时正确性(int/num/bool直通/大整数保真/错误路径)
This commit is contained in:
JianFeeeee
2026-08-25 09:29:24 +08:00
parent 42e8b7676d
commit 237aab3f36
13 changed files with 1091 additions and 112 deletions

View File

@ -24,6 +24,13 @@ typedef struct loaded_function
}ld_func;
// 结果类型标记typed interopv0.2.2
#define CJT_NIL 0
#define CJT_BOOL 1
#define CJT_INT 2
#define CJT_NUM 3
#define CJT_STR 4
#ifdef __cplusplus
class Lua_runner//lua运行器对象
{
@ -34,12 +41,31 @@ class Lua_runner//lua运行器对象
int unload_lib(const char *name);//解除加载
int loadfunction(const char *path,const char *name);//预加载函数(顶层执行,结果存入独立函数表)
int unloadfunction(const char *name);//卸载预加载函数
int callfunction(const char *name,const char *arg);//按名称调用已预加载的函数
int run(const char *path = NULL,const char *arg = NULL);
int callfunction(const char *name,const char *arg);//按名称调用已预加载的函数(字符串参数)
int callfunction_int(const char *name, long long val);//按名称调用,传 Int64 参数
int callfunction_num(const char *name, double val);//按名称调用,传 Float64 参数
int callfunction_bool(const char *name, int val);//按名称调用,传 Bool 参数
int callfunction_void(const char *name);//按名称调用,不带参数
int run(const char *path = NULL,const char *arg = NULL);//运行脚本(字符串参数)
int run_int(const char *path, long long val);//运行脚本,传 Int64 参数
int run_num(const char *path, double val);//运行脚本,传 Float64 参数
int run_bool(const char *path, int val);//运行脚本,传 Bool 参数
int run_void(const char *path);//运行脚本,不带参数
int clean();//清除状态机缓存
int dostring(const char *target);
std::string reslt;
lua_State *get_lua_State();
// typed interop最近一次调用的结果类型与值callfunction_*/run_* 更新)
int last_result_type; // CJT_NIL/CJT_BOOL/CJT_INT/CJT_NUM/CJT_STR
long long last_result_int;
double last_result_num;
int last_result_bool;
// 内部辅助:读取 Lua 栈顶值并记录类型到 last_result_*
void capture_result();
// 计算 lua_pcall 实际返回值数量并记录结果pop_results=true 时弹出全部返回值
// (管道模式的 run_* 传 false 以保留栈上数据供后续节点使用)
// 返回实际返回值数量
int finish_call(int pre_top, int nargs, bool pop_results);
private:
lua_State *L;
int pkg_cont;