Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.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/8/lua/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
C# 将对象从C传递到Lua脚本#_C#_Lua_Luainterface - Fatal编程技术网

C# 将对象从C传递到Lua脚本#

C# 将对象从C传递到Lua脚本#,c#,lua,luainterface,C#,Lua,Luainterface,我正在将LuaInterface与C#一起使用,并且已正确设置了所有内容 我希望能够做到的是,当使用lua.DoFile()启动脚本时,脚本可以访问我可以发送的播放器对象 当前代码: public static void RunQuest(string LuaScriptPath, QPlayer Player) { QMain.lua.DoFile(LuaScriptPath); } 但正如您所见,脚本将无法访问Player对象。我看到两个选项。第一个是使您的播放器成为Lua的全局变

我正在将LuaInterface与C#一起使用,并且已正确设置了所有内容

我希望能够做到的是,当使用lua.DoFile()启动脚本时,脚本可以访问我可以发送的播放器对象

当前代码:

public static void RunQuest(string LuaScriptPath, QPlayer Player)
{
    QMain.lua.DoFile(LuaScriptPath);
}

但正如您所见,脚本将无法访问Player对象。

我看到两个选项。第一个是使您的播放器成为Lua的全局变量:

QMain.lua['player'] = Player
然后您就可以在脚本中访问
player

第二个选项是让脚本定义一个接受player作为参数的函数。因此,如果当前脚本包含
…code…
,那么现在它将包含:

function RunQuest(player)
    ...code...
end
您的C#代码将如下所示:

public static void RunQuest(string LuaScriptPath, QPlayer Player)
{
    QMain.lua.DoFile(LuaScriptPath); // this will not actually run anything, just define a function
    QMain.lua.GetFunction('RunQuest').Call(player);        
}

我看到两种选择。第一个是使您的播放器成为Lua的全局变量:

QMain.lua['player'] = Player
然后您就可以在脚本中访问
player

第二个选项是让脚本定义一个接受player作为参数的函数。因此,如果当前脚本包含
…code…
,那么现在它将包含:

function RunQuest(player)
    ...code...
end
您的C#代码将如下所示:

public static void RunQuest(string LuaScriptPath, QPlayer Player)
{
    QMain.lua.DoFile(LuaScriptPath); // this will not actually run anything, just define a function
    QMain.lua.GetFunction('RunQuest').Call(player);        
}