Giter Site home page Giter Site logo

luasharp's Introduction

LuaSharp

A pair of libraries which provide both low and high level interfaces to the Lua API from .NET/Mono. Written in C# using MonoDevelop, should support Windows and Visual Studio out of the box.

luasharp's People

Contributors

jsimmons avatar

Stargazers

 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

luasharp's Issues

LuaFunction crash on Windows7 64-bit with Mono

Trying to write a function in C# (to redirect print's output to stdio to a GUI window). Works fine on Linux, but crashing on a Windows7 64-bit computer. (This is my first interaction with LuaSharp and Lua in general, so I might be doing something stupid). I am using the Lua Windows binaries for x86 (the ones made for 64-bit explicitly did not load from LuaSharp.dll).

Test code:

// CSharp code to assign Lua's print function

public static class LuaEnv {

public static void Main() {
LuaSharp.Lua state = new LuaSharp.Lua();
setEnvironment(state);
LuaSharp.LuaFunction p = (LuaSharp.LuaFunction)state["print"];
p.Call(1);
p.Call(2);
p.Call(3);
}

public static void setEnvironment(LuaSharp.Lua state) {
state["print"] = new MyPrint();
}

public class MyPrint : LuaSharp.ClrFunction {

public MyPrint() {
}

protected override object[] OnInvoke(LuaSharp.Lua state, object[] args) {
  System.Console.Write("MyPrint: ");
  System.Console.WriteLine(args[0]);
  return new object[] {null};
}

}
}

Compiled on Linux under Mono 2.6.7 with:

gmcs -target:exe \
    LuaTest.cs \
    -r:LuaSharp \
    -out:LuaTest.exe 

C:\Users\dblank\Desktop\Calico\languages\Lua>mono LuaTest.exe
MyPrint: 1
Stacktrace:

at (wrapper managed-to-native) LuaWrap.LuaLib.lua_call (intptr,int,int) <0x00004>
at (wrapper managed-to-native) LuaWrap.LuaLib.lua_call (intptr,int,int) <0x00004>
at LuaSharp.LuaFunction.Call (object[]) <0x000fa>
at LuaEnv.Main () <0x000ea>
at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) <0x0003a>

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

C:\Users\dblank\Desktop\Calico\languages\Lua>

I've also tried running with later versions of Mono, and it seems to crash after it does the print.

Any ideas appreciated!

-Doug

LuaTable to List?

How can one get a LuaTable into a C# list?

I have tried variations of:

public static System.Collections.Generic.List ToList(LuaSharp.LuaTable table) {
System.Collections.Generic.List list = new System.Collections.Generic.List();
System.Collections.Generic.KeyValuePair<object,object> pair in table) {
list.Add(pair.Key.ToString());
}
return list;
}

but, I get a Mono crash when I try to generate the KeyValue Enumerator.

Ideas?

-Doug

AccessViolationException when calling C# functions

I pushed a function on the stack using this:

lua["debug"] = new CallbackFunction(lua_Debug);

with lua_Debug as follows:

    internal static int lua_Debug(IntPtr state)
    {
        int args = 0;
        int stack = LuaLib.lua_gettop(state);
        if (stack == 2)
        {
            string format = LuaLib.lua_tostring(state, 1);
            string arg = LuaLib.lua_tostring(state, 2);
            Console.WriteLine(format, arg);
        }
        return args;
    }

Now when running the following lua code:
debug("TEST: {0}", "TEST")

I see that indeed, "TEST: TEST" appears on the console, as expected.. however, after returning the debugger kicks in to this section of LuaLib.cs:

    public static bool luaL_dofile( IntPtr state, string filename )
    {
        return ( luaL_loadfile( state, filename ) == LuaEnum.Ok ) && ( lua_pcall( state, 0, (int)LuaEnum.MultiRet, 0 ) == LuaEnum.Ok );
    }

with an AccessViolationException

using Lua51.dll versioned 5.1.4.0, and the last git export of LuaSharp and LuaWrap

any clues?

Adding an empty named table to the stack

In order to programatically run code like "var = { }" the following should be executed:

LuaLib.lua_newtable(handle);
LuaLib.lua_setglobal(handle, tableName);

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.