GithubHelp home page GithubHelp logo

aluminumlua's Introduction

AluminumLua

What?

A fast, lightweight Lua scripting engine written entirely in C#. It's called 'AluminumLua' (or 'alua' for short) as a poke at all those "iron" languages...

Architecture

AluminumLua does not use the DLR. Instead of generating an AST, the parser calls directly into an interface (IExecutor), that represents abstracted stack-based execution actions, such as Assignment or function Call.

This design enables different pluggable execution backends. Currently there is an InterpreterExecutor that directly executes the actions while the script is being parsed, and a CompilerExecutor that compiles a DynamicMethod.

The default execution policy uses the interpreter for the main script body and generates DynamicMethods for any defined function bodies.

Dependencies

.NET 4.0+ is required on Windows, or Mono 2.10+ anywhere else. There are no other dependencies.

Embed it

var context = new LuaContext ();
context.AddBasicLibrary ();
context.AddIoLibrary ();

context.SetGlobal ("some_func_in_lua", calls_this_func_in_csharp);
context.SetGlobal ("random_string", "hello");
// ...

var parser = new LuaParser (context, file_name); // < or leave file_name out to read stdin
parser.Parse ();

Building

Use Premake to generate a makefile or Visual Studio solution. Get it here: http://industriousone.com/premake/download

GNU Make

premake4 gmake
make

Visual Studio / Xamarin Studio / MonoDevelop / SharpDevelop

premake4 vs2010
(build the solution using your favorite tool)

The build produces the following products:

  • AluminumLua.dll is the script engine that can be referenced in other projects.
  • alua.exe is the command line interpreter. Pass a script file name or no arguments for a REPL.

Both products are self-contained and do not depend on the other.

After the Build

Run tests

premake4 test

Clean

premake4 clean

License

MIT/X11

aluminumlua's People

Contributors

chkn avatar gamemaster101gr avatar gleblebedev avatar nyashes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aluminumlua's Issues

for-loops not working??

Or am I just stupid? My lua code:

for i=1,10 do
    print(i)
end

return 'I\'m done!'

My C# code (worked perfectly for other Lua scripts, e.g. the helloworld one)

        static void Main(string[] args)
        {
            var context = new LuaContext();
            context.AddBasicLibrary();
            context.AddIoLibrary();

            var parser = new LuaParser(context, "helloworld.lua");
            parser.Parse();

            Console.ReadLine();
        }

Throws this exception:

"Error in helloworld.lua(1,5): syntax error"

Why??

[Request] Windows Store application version

I started to port the thing but came to that ILGenerator in ExpressionCompiler. I never used Reflection that much so I'm not familiar with how that works. Is there a way to do that without reflection (performance doesn't matter)

else statement variable context

Hi. I've noticed an issue with variable contexts in "else" statements. The following code:

bar = 0
function foo()
print "bar is " .. bar
if bar > 0 then
bar = 0
else
bar = bar + 1
end
end
foo()
foo()
foo()
foo()

Has the following output:
bar is 0
bar is 1
bar is 0
bar is 2

The "else" block seems to have its own local context for the "bar" variable which is remembered each time the block is executed. I wasn't able to figure out any workaround to this issue in the general case, although the above code can be edited to make the problem go away by not using an else statement.

Thanks again.

if then else execution order issue

Hi. Thanks for the work so far on AluminumLua. It's a project with great promise!

I'm noticing a significant scoping issue with "if" statements within function calls. The first is:

bar = 0
function foo()
print "start"
if bar == 0 then
print "bar is zero"
end
print "finish"
end
foo()

The output from this lua code is:
start
finish
bar is zero

The internal "then" block is executed after the outer block of the function "foo", printing "finish" before printing "bar is zero".

The code does not exhibit the problem if the "if" is scoped outside of a function, like so:

bar = 0
print "start"
if bar == 0 then
print "bar is zero"
end
print "finish"

Also you can work around it by making a separate function to execute the "if" block like so:

bar = 0
function ifBlock()
if bar == 0 then
print "bar is zero"
end
end
function foo()
print "start"
ifBlock()
print "finish"
end
foo()

But neither of these solutions are ideal!

Nested if/then/else doesn't work

if false then
    if false then
        print("two falses are true")
    else
        print("one false is true")
    end
else
    print("at least one false is false")
end

Expected output:
at least one false is true

Actual output:
Unhandled Exception:
AluminumLua.LuaException: Error in foo.lua(9,7): Expected 'then'

Parse Number Error!

I set a = 20 and excute the following script: value=27006.63+(value_1.25-27006.63)_0.991440392.An error occurred because of ParseNumberLiteral doesn't work correctly.

bug but where ???

Hi,

I hope you can help me with that because AluminiumLua seems a great project ...

I try this :

-- Fibonacci series

function Fibonacci(n)
if (n == 0) then
return (0)
elseif (n == 1) or (n == 2) then
return (1)
end
local a, b, c
a=0
b=1
for i=2,n,1 do
c=a+b
a=b
b=c
end
return b
end

print("Fibonacci(1 2 3 ... 12): ")
for n = 1,12,1 do
print(Fibonacci(n) .. " ")
end

and I get the following error :

Error in fib.lua(7,3): syntax error

Although this code works fine with some other parser like Luainterface ....

thanks in advance for any help,
Domi.

unexpected 'a'

I've noticed, that in your lib there is a bug/error.

When I paste such code:

//---
local aaa = 1
aaa = aaa + 1

print(aaa)
//---

or other variable name, that begins from 'a' letter, it throws me an error Exception:

A first chance exception of type 'AluminumLua.LuaException' occurred in WindowsPhoneGame3.DLL
Error in main.lua(2,3): unexpected 'a'

Do you have idea why?

PS.

I've noticed, that this error is caused by 'and' operator. You are trying to read operator, and when you find 'a' you want next letter to be 'n' and next 'd'. I think this could be done in other way, because now i cant use variable, that begins from 'a' letter.

Maybe you shuld use buffer for whole key-or-not-word, and when you will read whole word, you should compare it with key-word-table and variable-table. What do you think?

And why not on windows phone ?

Hello, so first thank you you're awesome :-)
Next This scripting language is the only one that I manage to make work on WP8 platform (ironpython : do not support, ironruby : do not work, standard LUA : too many things to change, ...) the only thing I needed to change was the reference to

Console.OpenStandardInput () //in LUAParser.cs 
/*to*/ Console.In

My question is can you make a nuget package for this platform by default, it would be great for every wp7/wp8 developer :-)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.