Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.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
.net 嵌入式Lua“;“打印”;不在Visual Studio的调试模式下工作_.net_Visual Studio_Lua_Embedded Language - Fatal编程技术网

.net 嵌入式Lua“;“打印”;不在Visual Studio的调试模式下工作

.net 嵌入式Lua“;“打印”;不在Visual Studio的调试模式下工作,.net,visual-studio,lua,embedded-language,.net,Visual Studio,Lua,Embedded Language,我正在使用Luainterface 2.0.3将Lua嵌入到c#应用程序中 一切正常,除了在VisualStudio的调试模式下,Lua的打印函数不会写入控制台(也不会写入输出) 在非调试模式下运行,打印工作正常 我错过什么了吗 谢谢 我没有使用LuaInterface,所以我不能确定,但您可能想尝试手动调用 io.output(io.stdout) 通过查看,它们解释了如何通过设置io.output重定向打印的输出位置。另见 我不确定这是否真的能解决问题,但是,因为我找不到任何与设置io.o

我正在使用Luainterface 2.0.3将Lua嵌入到c#应用程序中

一切正常,除了在VisualStudio的调试模式下,Lua的打印函数不会写入控制台(也不会写入输出)

在非调试模式下运行,打印工作正常

我错过什么了吗


谢谢

我没有使用LuaInterface,所以我不能确定,但您可能想尝试手动调用

io.output(io.stdout)
通过查看,它们解释了如何通过设置io.output重定向
打印的输出位置。另见


我不确定这是否真的能解决问题,但是,因为我找不到任何与设置io.output相关的内容。

不幸的是,您可能遇到了
print()
函数中的已知缺陷,该函数实际上是为了在控制台提示下进行快速而肮脏的调试,而且缺少一些必要的灵活性

由实现的基本库函数
print()
显式使用C运行时的
stdout
流作为其目标。由于它在实现中显式引用全局变量
stdout
,因此重定向它的唯一方法是使该文件句柄重定向。在C程序中,可以通过调用
freopen(stdout,…)
来完成。不幸的是,Lua中没有一个库函数可以做到这一点

io
库在中实现。它使用函数环境保存打开的文件描述符表,并在初始化期间为三个标准描述符创建名为
io.stdin
io.stdout
io.stderr
file
对象。它还提供名为
io.output
io.input
的函数,以允许修改这两个描述符,使其指向任何打开的
文件
对象(如果传递了文件名,则指向新打开的文件)。但是,这些函数只会更改函数环境表,而不会调用
freopen()
来修改C运行时的
文件
值表

我不知道LuaInterface如何尝试处理标准C运行时的
stdout
思想。很可能是
stdout
没有连接到VS调试器中任何有用的东西,因为它可能利用了某些.NET功能来捕获被调试模块的输出,而这些输出在任何情况下都可能与C不兼容

也就是说,很容易替换标准的
print
功能。只需使用LuaInterface的现有功能编写一个名为
print
的全局函数,该函数对每个参数调用
tostring()
,并将其传递给标准输出设备

替换文件“lua/etc/luavs.bat”中的第7行


并使用MSVCRT的调试版本重新编译lua。之后,您的输出将按预期重定向。

这里有一个代码示例,说明如何使用LuaInterface中使用的LuaDLL类重定向lua打印函数:

// See http://medek.wordpress.com/2009/02/03/wrapping-lua-errors-and-print-function/
static int LuaPrint(IntPtr L)
{
  int nArgs = LuaDLL.lua_gettop(L);
  LuaDLL.lua_getglobal(L, "tostring");
  string ret = ""; //this is where we will dump the output
  //make sure you start at 1 *NOT* 0
  for(int i = 1; i <= nArgs; i++)
  {
      LuaDLL.lua_pushvalue(L, -1);
      LuaDLL.lua_pushvalue(L, i);
      LuaDLL.lua_call(L, 1, 1);
      string s = LuaDLL.lua_tostring(L, -1);
      if(s == null)
          return LuaDLL.luaL_error(L, "\"tostring\" must return a string to \"print\"");
      if(i > 1) ret += "\t";
      ret += s;
      LuaDLL.lua_pop(L, 1);
  };
  //Send it wherever
  Console.Out.WriteLine(ret);
  return 0;
}
@set MYCOMPILE=cl /nologo /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE
@set MYCOMPILE=cl /nologo /MDd /Od /W3 /c /D_CRT_SECURE_NO_DEPRECATE
// See http://medek.wordpress.com/2009/02/03/wrapping-lua-errors-and-print-function/
static int LuaPrint(IntPtr L)
{
  int nArgs = LuaDLL.lua_gettop(L);
  LuaDLL.lua_getglobal(L, "tostring");
  string ret = ""; //this is where we will dump the output
  //make sure you start at 1 *NOT* 0
  for(int i = 1; i <= nArgs; i++)
  {
      LuaDLL.lua_pushvalue(L, -1);
      LuaDLL.lua_pushvalue(L, i);
      LuaDLL.lua_call(L, 1, 1);
      string s = LuaDLL.lua_tostring(L, -1);
      if(s == null)
          return LuaDLL.luaL_error(L, "\"tostring\" must return a string to \"print\"");
      if(i > 1) ret += "\t";
      ret += s;
      LuaDLL.lua_pop(L, 1);
  };
  //Send it wherever
  Console.Out.WriteLine(ret);
  return 0;
}
IntPtr luaState = LuaDLL.luaL_newstate();
LuaDLL.luaL_openlibs(luaState);
LuaDLL.lua_newtable(luaState);
LuaDLL.lua_setglobal(luaState, "luanet");
Lua l = new Lua(luaState.ToInt64());
LuaDLL.lua_register(luaState, "print", new LuaCSFunction(LuaPrint));