Exemple #1
0
        public CheckType(ObjectTranslator translator)
        {
            this.translator = translator;

            extractValues.Add(typeof(object).TypeHandle.Value.ToInt64(), new ExtractValue(getAsObject));
            extractValues.Add(typeof(sbyte).TypeHandle.Value.ToInt64(), new ExtractValue(getAsSbyte));
            extractValues.Add(typeof(byte).TypeHandle.Value.ToInt64(), new ExtractValue(getAsByte));
            extractValues.Add(typeof(short).TypeHandle.Value.ToInt64(), new ExtractValue(getAsShort));
            extractValues.Add(typeof(ushort).TypeHandle.Value.ToInt64(), new ExtractValue(getAsUshort));
            extractValues.Add(typeof(int).TypeHandle.Value.ToInt64(), new ExtractValue(getAsInt));
            extractValues.Add(typeof(uint).TypeHandle.Value.ToInt64(), new ExtractValue(getAsUint));
            extractValues.Add(typeof(long).TypeHandle.Value.ToInt64(), new ExtractValue(getAsLong));
            extractValues.Add(typeof(ulong).TypeHandle.Value.ToInt64(), new ExtractValue(getAsUlong));
            extractValues.Add(typeof(double).TypeHandle.Value.ToInt64(), new ExtractValue(getAsDouble));
            extractValues.Add(typeof(char).TypeHandle.Value.ToInt64(), new ExtractValue(getAsChar));
            extractValues.Add(typeof(float).TypeHandle.Value.ToInt64(), new ExtractValue(getAsFloat));
            extractValues.Add(typeof(decimal).TypeHandle.Value.ToInt64(), new ExtractValue(getAsDecimal));
            extractValues.Add(typeof(bool).TypeHandle.Value.ToInt64(), new ExtractValue(getAsBoolean));
            extractValues.Add(typeof(string).TypeHandle.Value.ToInt64(), new ExtractValue(getAsString));
            extractValues.Add(typeof(LuaFunction).TypeHandle.Value.ToInt64(), new ExtractValue(getAsFunction));
            extractValues.Add(typeof(LuaTable).TypeHandle.Value.ToInt64(), new ExtractValue(getAsTable));
            extractValues.Add(typeof(LuaUserData).TypeHandle.Value.ToInt64(), new ExtractValue(getAsUserdata));
            
            extractNull = new ExtractValue(getNull);
            extractNetObject = new ExtractValue(getAsNetObject);
        }
Exemple #2
0
        // lockCallback, unlockCallback; used by debug code commented out for now

        public LuaInterface()
        {
            luaState = LuaDLL.luaL_newstate();	// steffenj: Lua 5.1.1 API change (lua_open is gone)
            luaState.initializing = true;
            //LuaDLL.luaopen_base(luaState);	// steffenj: luaopen_* no longer used
            LuaDLL.luaL_openlibs(luaState);		// steffenj: Lua 5.1.1 API change (luaopen_base is gone, just open all libs right here)
            LuaDLL.lua_pushstring(luaState, "LUAINTERFACE LOADED");
            LuaDLL.lua_pushboolean(luaState, true);
            LuaDLL.lua_settable(luaState, (int)LuaIndexes.LUA_REGISTRYINDEX);
            LuaDLL.lua_newtable(luaState);
            LuaDLL.lua_setglobal(luaState, "luanet");
            LuaDLL.lua_pushvalue(luaState, (int)LuaIndexes.LUA_GLOBALSINDEX);
            LuaDLL.lua_getglobal(luaState, "luanet");
            LuaDLL.lua_pushstring(luaState, "getmetatable");
            LuaDLL.lua_getglobal(luaState, "getmetatable");
            LuaDLL.lua_settable(luaState, -3);
            LuaDLL.lua_replace(luaState, (int)LuaIndexes.LUA_GLOBALSINDEX);
            translator = new ObjectTranslator(this, luaState);
            LuaDLL.lua_replace(luaState, (int)LuaIndexes.LUA_GLOBALSINDEX);

            tracebackFunction = new SharpLua.Lua.lua_CFunction(traceback);

            // We need to keep this in a managed reference so the delegate doesn't get garbage collected
            panicCallback = new SharpLua.Lua.lua_CFunction(PanicCallback);
            Lua.lua_CFunction oldpanicFunc =
                //LuaDLL.lua_atpanic(luaState, tracebackFunction);
                LuaDLL.lua_atpanic(luaState, panicCallback);

            DoString(ScriptStrings.InitLuaNet, "LuaNet");
            DoString(ScriptStrings.InitClrLib, "ClrLib");
            DoString(ScriptStrings.InitExtLib, "ExtLib");
            luaState.initializing = false;
            luaState.SetInterface(this);
        }
Exemple #3
0
 public MetaFunctions(ObjectTranslator translator)
 {
     this.translator = translator;
     gcFunction = new SharpLua.Lua.lua_CFunction(this.collectObject);
     toStringFunction = new SharpLua.Lua.lua_CFunction(this.toString);
     indexFunction = new SharpLua.Lua.lua_CFunction(this.getMethod);
     newindexFunction = new SharpLua.Lua.lua_CFunction(this.setFieldOrProperty);
     baseIndexFunction = new SharpLua.Lua.lua_CFunction(this.getBaseMethod);
     callConstructorFunction = new SharpLua.Lua.lua_CFunction(this.callConstructor);
     classIndexFunction = new SharpLua.Lua.lua_CFunction(this.getClassMethod);
     classNewindexFunction = new SharpLua.Lua.lua_CFunction(this.setClassFieldOrProperty);
     execDelegateFunction = new SharpLua.Lua.lua_CFunction(this.runFunctionDelegate);
     //new String()
 }
Exemple #4
0
        /*
         * Constructs the wrapper for a known MethodBase instance
         */
        public LuaMethodWrapper(ObjectTranslator translator, object target, IReflect targetType, MethodBase method)
        {
            _Translator = translator;
            _Target = target;
            _TargetType = targetType;
            if (targetType != null)
                _ExtractTarget = translator.typeChecker.getExtractor(targetType);
            _Method = method;
            _MethodName = method.Name;

            if (method.IsStatic)
            { _BindingType = BindingFlags.Static; }
            else
            { _BindingType = BindingFlags.Instance; }
        }
 public ClassGenerator(ObjectTranslator translator, Type klass)
 {
     this.translator = translator;
     this.klass = klass;
 }
 public DelegateGenerator(ObjectTranslator translator, Type delegateType)
 {
     this.translator = translator;
     this.delegateType = delegateType;
 }
Exemple #7
0
        /// <summary>
        /// Debug tool to dump the lua stack
        /// </summary>
        /// FIXME, move somewhere else
        public static void dumpStack(ObjectTranslator translator, SharpLua.Lua.LuaState luaState)
        {
            int depth = LuaDLL.lua_gettop(luaState);

            Debug.WriteLine("lua stack depth: " + depth);
            for (int i = 1; i <= depth; i++)
            {
                LuaTypes type = LuaDLL.lua_type(luaState, i);
                // we dump stacks when deep in calls, calling typename while the stack is in flux can fail sometimes, so manually check for key types
                string typestr = (type == LuaTypes.LUA_TTABLE) ? "table" : LuaDLL.lua_typename(luaState, type);

                string strrep = LuaDLL.lua_tostring(luaState, i);
                if (type == LuaTypes.LUA_TUSERDATA)
                {
                    object obj = translator.getRawNetObject(luaState, i);
                    strrep = obj.ToString();
                }

                Debug.Print("{0}: ({1}) {2}", i, typestr, strrep);
            }
        }
Exemple #8
0
        /*
         * Constructs the wrapper for a known method name
         */
        public LuaMethodWrapper(ObjectTranslator translator, IReflect targetType, string methodName, BindingFlags bindingType)
        {
            _Translator = translator;
            _MethodName = methodName;
            _TargetType = targetType;

            if (targetType != null)
                _ExtractTarget = translator.typeChecker.getExtractor(targetType);

            _BindingType = bindingType;

            //CP: Removed NonPublic binding search and added IgnoreCase
            _Members = targetType.UnderlyingSystemType.GetMember(methodName, MemberTypes.Method, bindingType | BindingFlags.Public | BindingFlags.IgnoreCase/*|BindingFlags.NonPublic*/);
        }
Exemple #9
0
        public virtual void Dispose()
        {
            if (translator != null)
            {
                translator.pendingEvents.Dispose();
                translator = null;
            }

            this.Close();
            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();
        }
Exemple #10
0
        /// <summary>
        /// CAUTION: LuaInterface's can't share the same lua state!
        /// </summary>
        /// <param name="lState"></param>
        public LuaInterface(SharpLua.Lua.LuaState lState)
        {
            lState.initializing = true;
            LuaDLL.lua_pushstring(lState, "LUAINTERFACE LOADED");
            LuaDLL.lua_gettable(lState, (int)LuaIndexes.LUA_REGISTRYINDEX);

            if (LuaDLL.lua_toboolean(lState, -1))
            {
                LuaDLL.lua_settop(lState, -2);
                throw new LuaException("There is already a LuaInterface associated with this LuaState");
            }
            else
            {
                LuaDLL.lua_settop(lState, -2);
                LuaDLL.lua_pushstring(lState, "LUAINTERFACE LOADED");
                LuaDLL.lua_pushboolean(lState, true);
                LuaDLL.lua_settable(lState, (int)LuaIndexes.LUA_REGISTRYINDEX);
                this.luaState = lState;
                LuaDLL.lua_pushvalue(lState, (int)LuaIndexes.LUA_GLOBALSINDEX);
                LuaDLL.lua_getglobal(lState, "luanet");
                LuaDLL.lua_pushstring(lState, "getmetatable");
                LuaDLL.lua_getglobal(lState, "getmetatable");
                LuaDLL.lua_settable(lState, -3);
                LuaDLL.lua_replace(lState, (int)LuaIndexes.LUA_GLOBALSINDEX);
                translator = new ObjectTranslator(this, this.luaState);
                LuaDLL.lua_replace(lState, (int)LuaIndexes.LUA_GLOBALSINDEX);
                DoString(ScriptStrings.InitLuaNet, "LuaNet");
                DoString(ScriptStrings.InitClrLib, "ClrLib");
                DoString(ScriptStrings.InitExtLib, "ExtLib");
            }
            _StatePassed = true;
            lState.initializing = false;
        }