调用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);
相关推荐
mjhcsp31 分钟前
C++ 背包DP解析
开发语言·c++
尘缘浮梦42 分钟前
协程asyncio入门案例 2
开发语言·python
juleskk1 小时前
2.15 复试训练
开发语言·c++·算法
一个处女座的程序猿O(∩_∩)O1 小时前
Python面向对象的多态特性详解
开发语言·python
yngsqq1 小时前
多段线顶点遍历技巧(适用闭合和非闭合)
开发语言
宇木灵1 小时前
C语言基础-五、数组
c语言·开发语言·学习·算法
xyq20242 小时前
空对象模式
开发语言
不懒不懒3 小时前
【Python办公自动化进阶指南:系统交互与网页操作实战】
开发语言·python·交互
会周易的程序员3 小时前
cNetgate插件架构设计详解 动态库 脚本二开lua, python, javascript
javascript·c++·python·物联网·lua·iot
普通网友3 小时前
C++与Rust交互编程
开发语言·c++·算法