调用Lua脚本tostring(xxx)报attempt to call a nil value (global ‘tostring‘

在c++程序里调用Lua脚本, 脚本中用到了转字符串 tostring(xxx)

Lua 复制代码
str = "test" 
function output(a,b,c)
    d = "a:"..tostring(a).."b:"..tostring(b).."c"..tostring(c)
    return d 
end

实际运行会报错:

attempt to call a nil value (global 'tostring')错误

解决方法:

在c++代码的L = luaL_newstate();下添加:

Lua 复制代码
luaopen_base(L); 或者 luaL_openlibs(L);
相关推荐
江畔柳前堤1 小时前
roLabelImg 详细安装教程
开发语言·人工智能·后端·云原生
Wang's Blog2 小时前
Go-Zero 项目开发47:自研微服务框架的必要性与核心结构设计
开发语言·微服务·golang
白鸽(二般)2 小时前
MinIO Java Client API
java·开发语言
hPw0eKIqD2 小时前
C++ 模板参数推导问题小记(非推导上下文)
开发语言·c++
临床数据科学和人工智能兴趣组3 小时前
要使用 R Markdown,首先需要安装 R 和 RStudio,接着安装 rmarkdown 包
开发语言·数据挖掘·数据分析·r语言·r语言-4.2.1
Nebula嵌入式3 小时前
【C语言】09-深入解析main函数
linux·c语言·开发语言·嵌入式
神罚天下ET5 小时前
c# ACME client (补充)
开发语言·c#
小灰灰搞电子5 小时前
Qt 实现魔法导航菜单源码分享
开发语言·qt
持敬chijing5 小时前
Python概述
开发语言·python
qq_370773097 小时前
Unity游戏xLua逆向实战:从SO版本识别到Lua脚本热替换全链路
游戏·unity·lua