tags:

views:

209

answers:

3

Does anyone know of any DLLs (preferably .net) that encapsulate the lua 5.1 compiler? I'm working on a .net project where part of it needs to compile lua scripts, and i would rather have a DLL that i could send script code to instead of sending the script to a temporary file and running luac.exe.

Edit: I'd need a .NET library that implements luac in such a way that it outputs standard lua bytecode (not a lua library that compiles to the CLR). Compiling the lua c source code didn't work, as when i went to include a reference to the dll in a c# project, visual studio complained that it wasnt a valid assembly. My searches so far haven't found anything.

+1  A: 

all the code for luac is distributed with lua... would be trivial to make it a DLL.

Keith Nicholas
+1  A: 

There is the Lua.NET project for Lua and .Net integration:

http://www.lua.inf.puc-rio.br/projects/luanet/

Alexander Gladysh
A: 

You can emulate luac in Lua, through the following command taken from the lua-users wiki:

lua -e 'io.write(string.dump(assert(loadfile())))' <sample.lua >sample.out

So if you were going to do that at the API level in C (even though I know you're using .NET), it should be something like

lua_dostring(L, "string.dump(assert(loadstring([==[YOUR CODE HERE]==])))");
size_t sz;
char *output = lua_tolstring(L, -1, &sz);

And then just save sz characters to your output file.

I realize this is a bit of a late answer, but since there wasn't already one here, I figured I'd take a stab at it.

Mark Rushakoff