Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么是C++;can';看不到我的lua脚本文件? 我有一个简单的问题,将Lua和C++结合起来。 我在Visual Studio中有我的项目: _C++_Lua - Fatal编程技术网

为什么是C++;can';看不到我的lua脚本文件? 我有一个简单的问题,将Lua和C++结合起来。 我在Visual Studio中有我的项目:

为什么是C++;can';看不到我的lua脚本文件? 我有一个简单的问题,将Lua和C++结合起来。 我在Visual Studio中有我的项目: ,c++,lua,C++,Lua,我运行lua_init()函数: bool lua_init(std::string &luaScriptName){ // Create the Lua state. Explanation from Lua 5.1 Ref. Manual: globalL = luaL_newstate(); // 5.1 OK - Lua 5.0 or lower will probably require different commands if( globalL == NULL )

我运行lua_init()函数:

bool lua_init(std::string &luaScriptName){
// Create the Lua state. Explanation from Lua 5.1 Ref. Manual:

globalL = luaL_newstate(); // 5.1 OK - Lua 5.0 or lower will probably require different commands

if( globalL == NULL )
    return false;

    // Loads all Lua standard libraries
luaL_openlibs(globalL);  // 5.1 OK - Lua 5.0 or lower will require different commands

// This lot below could be replaced with luaL_dofile, but that just does: luaL_loadfile(..) || lua_pcall(..), which gives no reporting of error messages etc.
int initError = luaL_loadfile(globalL,luaScriptName.c_str());
switch( initError )
{
    case 0:
        // The file loaded okay, so call it as a protected function - to stop fatal errors from exiting the program
        lua_pcall(globalL,0,0,0);
        break;
    case LUA_ERRFILE:
        std::cerr<<"Cannot find / open lua script file: "<<luaScriptName<<std::endl<<"Skipping Lua init."<<std::endl;
        break;
    case LUA_ERRSYNTAX:
        std::cerr<<"Syntax error during pre-compilation of script file: " <<luaScriptName<<std::endl<<"Skipping Lua init."<<std::endl;
        break;
    case LUA_ERRMEM:
        // Treating this as fatal, since it means other Lua calls are unlikely to work either
        std::cerr<<"Fatal memory allocation error during processing of script file: " <<luaScriptName<<std::endl;
        return false;
}
return true;
bool lua_init(std::string&luaScriptName){
//创建Lua状态。Lua 5.1参考手册中的说明:
globalL=luaL_newstate();//5.1确定-Lua 5.0或更低版本可能需要不同的命令
if(globalL==NULL)
返回false;
//加载所有Lua标准库
luaL_openlibs(globalL);//5.1正常-Lua 5.0或更低版本需要不同的命令
//下面这一部分可以用luaL_dofile替换,但实际上是这样的:luaL_loadfile(..)| lua_pcall(..),它不会报告错误消息等。
int initError=luaL_loadfile(globalL,luaScriptName.c_str());
开关(初始化错误)
{
案例0:
//加载的文件没有问题,因此将其作为受保护的函数调用-以阻止致命错误退出程序
lua_pcall(globalL,0,0,0);
打破
案例LUA_ERRFILE:

std::cerr您的代码将在二进制文件所在的位置执行,或者在调试模式下在目标目录中执行。因此,请检查您的lua文件在执行时是否可被二进制文件访问。如果它与源文件一起,则肯定无法访问。

感谢您的响应。我已更改了Visual Studio的工作目录,并将我的sc放入其中ipt.lua.我没有发现关于找不到文件的错误,但是脚本没有被执行-我在控制台中没有看到HelloWorld。因此1.我的答案是正确的,然后检查它!2.我不知道你的脚本应该做什么!3.如果你的脚本应该打印hello world,请检查你的lua vm的输出是否是控制台。我真的我怀疑你的虚拟机输出是否符合标准输出,但你必须检查自己。无论如何,如果你没有任何错误,那么脚本就被加载了(它是否运行?我不记得它是否足以加载它),所以请查看lua代码。好的,首先我的脚本是:
print(“hello world”);
其次:我在VS中创建了一个新项目(不是用OGRePAPWAZER而是普通C++项目),并把相同的文件复制到它里面,现在一切都运行得很好。我认为问题是OGRE更具体——正如你说的关于Lua VM的东西——我如何检查它?检查Lua doc。如果我没记错的话,有办法打印打印()。函数输出到某个特定的输出,但默认情况下,它将输出到C标准输出,在您的情况下可能会被禁用或类似的情况。只需检查它当前的位置,将其重新连接到输出设备,您就会使其运行。您忘了“检查”我的答案吗?:)我将尝试查看lua文档(但正如我最近所看到的,这对我来说是相当复杂的:()。我找到了这段代码来运行ogre中的console:我已经把它放进了我的代码中,但除了许多不同的东西之外,我看不到lua脚本的“Hello World”顺便说一句。sry我无法“检查”你的答案,因为我没有太多的信誉点:(