Ejemplo n.º 1
0
 public Lua()
 {
     luaState = new LuaState();
     Init();
     // We need to keep this in a managed reference so the delegate doesn't get garbage collected
     panicCallback = PanicCallback;
     luaState.AtPanic(panicCallback);
 }
Ejemplo n.º 2
0
        private int GetMethodSignatureInternal(LuaState luaState)
        {
            ProxyType klass;
            object    target;
            int       udata = luaState.CheckUObject(1, "luaNet_class");

            if (udata != -1)
            {
                klass  = (ProxyType)_objects[udata];
                target = null;
            }
            else
            {
                target = GetRawNetObject(luaState, 1);

                if (target == null)
                {
                    ThrowError(luaState, "get_method_bysig: first arg is not type or object reference");
                    luaState.PushNil();
                    return(1);
                }

                klass = new ProxyType(target.GetType());
            }

            string methodName = luaState.ToString(2, false);
            var    signature  = new Type[luaState.GetTop() - 2];

            for (int i = 0; i < signature.Length; i++)
            {
                signature[i] = FindType(luaState.ToString(i + 3, false));
            }

            try
            {
                var method = klass.GetMethod(methodName, BindingFlags.Public | BindingFlags.Static |
                                             BindingFlags.Instance, signature);
                var wrapper = new LuaMethodWrapper(this, target, klass, method);
                LuaNativeFunction invokeDelegate = wrapper.InvokeFunction;
                PushFunction(luaState, invokeDelegate);
            }
            catch (Exception e)
            {
                ThrowError(luaState, e);
                luaState.PushNil();
            }

            return(1);
        }
Ejemplo n.º 3
0
        public ObjectTranslator(Lua interpreter, LuaState luaState)
        {
            _tagPtr          = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)));
            this.interpreter = interpreter;
            typeChecker      = new CheckType(this);
            metaFunctions    = new MetaFunctions(this);
            assemblies       = new List <Assembly>();

            _importTypeFunction        = ImportType;
            _loadAssemblyFunction      = LoadAssembly;
            _registerTableFunction     = RegisterTable;
            _unregisterTableFunction   = UnregisterTable;
            _getMethodSigFunction      = GetMethodSignature;
            _getConstructorSigFunction = GetConstructorSignature;
            _ctypeFunction             = CType;
            _enumFromIntFunction       = EnumFromInt;

            CreateLuaObjectList(luaState);
            CreateIndexingMetaFunction(luaState);
            CreateBaseClassMetatable(luaState);
            CreateClassMetatable(luaState);
            CreateFunctionMetatable(luaState);
            SetGlobalFunctions(luaState);
        }
Ejemplo n.º 4
0
 /*
  * Pushes a delegate into the stack
  */
 internal void PushFunction(LuaState luaState, LuaNativeFunction func)
 {
     PushObject(luaState, func, "luaNet_function");
 }
Ejemplo n.º 5
0
 public LuaFunction(LuaNativeFunction nativeFunction, Lua interpreter) : base(0)
 {
     function     = nativeFunction;
     _Interpreter = interpreter;
 }
Ejemplo n.º 6
0
 internal void PushCSFunction(LuaNativeFunction function)
 {
     translator.PushFunction(luaState, function);
 }
Ejemplo n.º 7
0
 public LuaFunction(int reference, Lua interpreter) : base(reference)
 {
     function     = null;
     _Interpreter = interpreter;
 }
Ejemplo n.º 8
0
 public LuaFunction(LuaNativeFunction nativeFunction, Lua interpreter) : base(0, interpreter)
 {
     function = nativeFunction;
 }
Ejemplo n.º 9
0
 public LuaFunction(int reference, Lua interpreter) : base(reference, interpreter)
 {
     function = null;
 }
Ejemplo n.º 10
0
 public LuaFunction(LuaNativeFunction nativeFunction, Lua interpreter)
 {
     _Reference   = 0;
     function     = nativeFunction;
     _Interpreter = interpreter;
 }
Ejemplo n.º 11
0
 public LuaFunction(int reference, Lua interpreter)
 {
     _Reference   = reference;
     function     = null;
     _Interpreter = interpreter;
 }