2011-10-11 57 views
1

我正在使用LuaInterface与C#,并已正确设置了一切。将对象传递给来自C#的Lua脚本#

我希望能够做的是,当脚本使用lua.DoFile(),脚本访问Player对象,我可以送...开始

目前代码:

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

但是,正如您所看到的脚本将无法访问Player对象。

回答

5

我看到两个选项。第一个是让你的播放器Lua的一个全局变量:

QMain.lua['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);   
} 
+0

使用QMain.lua [ “玩家”] =播放机,工作得很好。 谢谢! – FrenchyNZ

相关问题