I have a C# program executing Lua scripts using the LuaInterface. So far, it is working well, unless my Lua script requires a specific package, like LuaXML.
I want to send an XML string from C# to a Lua function.
This is the XML, saved in C:\temp:
<?xml version="1.0" encoding="utf-16" ?>
<library id="101">
<book id="10" author="Balzac" title="Le Père Goriot"></book>
<book id="20" quantity="Stendhal" price="Le Rouge et le noir"></book>
</library>
This is the C# code:
Lua lua = new Lua();
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(@"C:\temp\library.xml");
lua.DoFile(@"C:\temp\myScript.lua");
LuaFunction luaFunction = lua.GetFunction("transformXML");
Object o = luaFunction.Call(xmlDocument.OuterXml);
This is the Lua script, saved on C\temp:
require("LuaXML")
function transformXML(input)
x = xml.eval(input)
output = nil
local library = x:find("library")
return library[1].id
end
local s = '<?xml version="1.0" encoding="utf-16" ?><library id="101"><book id="10" author="Balzac" title="Le Père Goriot"></book><book id="20" quantity="Stendhal" price="Le Rouge et le noir"></book></library>'
print(transformXML(s))
This is the error I got:
C:\temp\myScript.lua:1: module 'LuaXML' not found:
no field package.preload['LuaXML']
no file '.\LuaXML.lua'
no file 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\lua\LuaXML.lua'
no file 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\lua\LuaXML\init.lua'
no file 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\LuaXML.lua'
no file 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\LuaXML\init.lua'
no file 'C:\Program Files (x86)\Lua\5.1\lua\LuaXML.luac'
no file '.\LuaXML.dll'
no file 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\LuaXML.dll'
no file 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\loadall.dll'
Do I have to put all these files (.lua, .dll) manually to all these locations?
The Lua script works when I execute it from the Lua console. It returns 10, the id of the first book.
Also, as mentionned, I was able to call Lua functions from C# as long as there is no 'require' in the script. It is not only LuaXML that throws that type of exception. Any package would.
I've played with the environment variables, but was not successful. However, I am not very good at that.
Thank you in advance for the help.