调用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);
相关推荐
疯狂吧小飞牛16 小时前
Lua C API 中的注册表介绍
java·c语言·lua
寻找华年的锦瑟16 小时前
Qt-配置文件(INI/JSON/XML)
开发语言·qt
HY小海16 小时前
【C++】AVL树实现
开发语言·数据结构·c++
workflower16 小时前
Fundamentals of Architectural Styles and patterns
开发语言·算法·django·bug·结对编程
Roc-xb16 小时前
ModuleNotFoundError: No module named ‘conda_token‘
开发语言·python·conda
人工干智能17 小时前
Python 开发中:`.ipynb`(Jupyter Notebook 文件)和 `.py`(Python 脚本文件)
开发语言·python·jupyter
Jay-juice17 小时前
QT信号与槽
开发语言·qt
fs哆哆17 小时前
在VB.NET中,有没有 ?.这个运算符
java·开发语言·.net
驰羽17 小时前
[GO]什么是热重载,如何使用Air工具
开发语言·后端·golang
傻啦嘿哟17 小时前
Python爬取B站视频评论区情感分析:从数据采集到价值挖掘
开发语言·python