Lua is a scripting language written in C language, and the LUA interpreter is easy to embed in the host language library. Its lightweight, easy to expand features by the vast number of developers love. Here we can get LuaInterFace.dll files through Luaforwindows or Luainterface. Here we provide luainterface package, convenient for everyone to download click on the Open link. The package not only contains LuaInterface.dll also contains Luanet.dell and Lua51.dll files, very convenient.
"Configuring the Development environment"
We use command win key +r input devenv, enter is open VS, at this time a new project. Add the above three DLL files to the project, as shown in the following figure:
At this point we select the reference right----->>>> Add Reference----->>>> Browse the location of the project to open the engineering directory, select LuaInterface.dll, OK. As shown in the figure:
The reference is complete as shown in the figure:
"Call Lua code in C #"
And be happy in the project. Enter the following code:
OK, let's start the project test. If you are x86 the system gets the results as follows:
If you are a x64 system, you will be surprised to find that the error on the header indicated: "DLL" Luanet.dll could not be loaded: The specified module could not be found. (Exception from hresult:0x8007007e). ”
Unable to find the specified module file, we suspect that the DLL file is missing from the Debug folder. We copied all three files to the directory and ran it again. Found it normal.
"Attention"
1, we repeatedly try to remove any of these three files have tried three failed, indicating that these three DLL files are required files. If a DLL is found in the project compilation that cannot be found ("Lua51.dll"
or ("Luanet.dll"). At this point you need Lua51.dll and Luanet.dll files in the debug build directory.
2, if the Compile Times "luainterface.luaexception:" [string "Chunk"]: 1: ' = ' excrpted near ' "", this time the Lua file encoding format to the UTF-8 format is good