예제 #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(Vector3).TypeHandle.Value.ToInt64(), new ExtractValue(getAsVector3));

            extractValues.Add(typeof(Vector2).TypeHandle.Value.ToInt64(), new ExtractValue(getAsVector2));
            extractValues.Add(typeof(Quaternion).TypeHandle.Value.ToInt64(), new ExtractValue(getAsQuaternion));
            extractValues.Add(typeof(Color).TypeHandle.Value.ToInt64(), new ExtractValue(getAsColor));
            extractValues.Add(typeof(Vector4).TypeHandle.Value.ToInt64(), new ExtractValue(getAsVector4));
            extractValues.Add(typeof(Ray).TypeHandle.Value.ToInt64(), new ExtractValue(getAsRay));
            extractValues.Add(typeof(Bounds).TypeHandle.Value.ToInt64(), new ExtractValue(getAsBounds));
                    

            extractNetObject = new ExtractValue(getAsNetObject);
        }
예제 #2
0
		public Lua() 
		{
			luaState = LuaDLL.luaL_newstate();	// steffenj: Lua 5.1.1 API change (lua_open is gone)
			//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);
			LuaDLL.luaL_dostring(luaState, Lua.init_luanet);	// steffenj: lua_dostring renamed to luaL_dostring

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

            // LuaDLL.lua_atlock(luaState, lockCallback = new LuaCSFunction(LockCallback));
            // LuaDLL.lua_atunlock(luaState, unlockCallback = new LuaCSFunction(UnlockCallback));
        }
예제 #3
0
 public Lua(long luaState)
 {
     this.luaLock = new object();
     IntPtr ptr = new IntPtr(luaState);
     LuaJIT.lua_pushstring(ptr, "LUAINTERFACE LOADED");
     LuaJIT.lua_gettable(ptr, -10000);
     if ((LuaJIT.lua_toboolean(ptr, -1) == 0 ? false : true))
     {
         LuaJIT.lua_settop(ptr, -2);
         throw new LuaException("There is already a LuaInterface.Lua instance associated with this Lua state");
     }
     LuaJIT.lua_settop(ptr, -2);
     LuaJIT.lua_pushstring(ptr, "LUAINTERFACE LOADED");
     LuaJIT.lua_pushboolean(ptr, 1);
     LuaJIT.lua_settable(ptr, -10000);
     this.luaState = ptr;
     LuaJIT.lua_pushvalue(ptr, -10002);
     LuaJIT.lua_getglobal(ptr, "luanet");
     LuaJIT.lua_pushstring(ptr, "getmetatable");
     LuaJIT.lua_getglobal(ptr, "getmetatable");
     LuaJIT.lua_settable(ptr, -3);
     LuaJIT.lua_replace(ptr, -10002);
     this.translator = new ObjectTranslator(this, this.luaState);
     LuaJIT.lua_replace(ptr, -10002);
     LuaJIT.luaL_dostring(ptr, init_luanet);
     this._StatePassed = true;
 }
예제 #4
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));

            extractNetObject = new ExtractValue(getAsNetObject);
        }
예제 #5
0
		/*
		 * Constructs the wrapper for a known method name
		 */
		public LuaMethodWrapper(ObjectTranslator translator, IReflect targetType, string methodName, BindingFlags bindingType) 
		{
			this.translator=translator;
			this.methodName=methodName;
			this.targetType=targetType;
			if(targetType!=null)
				extractTarget=translator.typeChecker.getExtractor(targetType);
			this.bindingType=bindingType;
			members=targetType.UnderlyingSystemType.GetMember(methodName,MemberTypes.Method,bindingType|BindingFlags.Public|BindingFlags.NonPublic);
		}
예제 #6
0
		/*
		 * Constructs the wrapper for a known MethodBase instance
		 */
		public LuaMethodWrapper(ObjectTranslator translator, object target, IReflect targetType, MethodBase method) 
		{
			this.translator=translator;
			this.target=target;
			this.targetType=targetType;
			if(targetType!=null)
				extractTarget=translator.typeChecker.getExtractor(targetType);
			this.method=method;
			this.methodName=method.Name;
			if(method.IsStatic) { bindingType=BindingFlags.Static; } 
			else { bindingType=BindingFlags.Instance; }
		}
예제 #7
0
 public LuaMethodWrapper(ObjectTranslator translator, IReflect targetType, string methodName, BindingFlags bindingType)
 {
     this._LastCalledMethod = new MethodCache();
     this._Translator = translator;
     this._MethodName = methodName;
     this._TargetType = targetType;
     if (targetType != null)
     {
         this._ExtractTarget = translator.typeChecker.getExtractor(targetType);
     }
     this._BindingType = bindingType;
     this._Members = targetType.UnderlyingSystemType.GetMember(methodName, MemberTypes.Method, (bindingType | BindingFlags.Public) | BindingFlags.IgnoreCase);
 }
예제 #8
0
 public MetaFunctions(ObjectTranslator translator)
 {
     this.translator = translator;
     gcFunction = new LuaCSFunction(this.collectObject);
     toStringFunction = new LuaCSFunction(this.toString);
     indexFunction = new LuaCSFunction(this.getMethod);
     newindexFunction = new LuaCSFunction(this.setFieldOrProperty);
     baseIndexFunction = new LuaCSFunction(this.getBaseMethod);
     callConstructorFunction = new LuaCSFunction(this.callConstructor);
     classIndexFunction = new LuaCSFunction(this.getClassMethod);
     classNewindexFunction = new LuaCSFunction(this.setClassFieldOrProperty);
     execDelegateFunction = new LuaCSFunction(this.runFunctionDelegate);
 }
예제 #9
0
 public static void dumpStack(ObjectTranslator translator, IntPtr luaState)
 {
     int num = LuaDLL.lua_gettop(luaState);
     for (int i = 1; i <= num; i++)
     {
         LuaTypes type = LuaDLL.lua_type(luaState, i);
         if (type != LuaTypes.LUA_TTABLE)
         {
             LuaDLL.lua_typename(luaState, type);
         }
         LuaDLL.lua_tostring(luaState, i);
         if (type == LuaTypes.LUA_TUSERDATA)
         {
             translator.getRawNetObject(luaState, i).ToString();
         }
     }
 }
예제 #10
0
 public LuaMethodWrapper(ObjectTranslator translator, object target, IReflect targetType, MethodBase method)
 {
     this._LastCalledMethod = new MethodCache();
     this._Translator = translator;
     this._Target = target;
     this._TargetType = targetType;
     if (targetType != null)
     {
         this._ExtractTarget = translator.typeChecker.getExtractor(targetType);
     }
     this._Method = method;
     this._MethodName = method.Name;
     if (method.IsStatic)
     {
         this._BindingType = BindingFlags.Static;
     }
     else
     {
         this._BindingType = BindingFlags.Instance;
     }
 }
예제 #11
0
        /// <summary>
        /// Debug tool to dump the lua stack
        /// </summary>
        /// FIXME, move somewhere else
        public static void dumpStack(ObjectTranslator translator, IntPtr 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);
            }
        }
예제 #12
0
 public Lua()
 {
     this.luaLock = new object();
     this.luaState = LuaJIT.luaL_newstate();
     LuaJIT.luaL_openlibs(this.luaState);
     LuaJIT.lua_pushstring(this.luaState, "LUAINTERFACE LOADED");
     LuaJIT.lua_pushboolean(this.luaState, 1);
     LuaJIT.lua_settable(this.luaState, -10000);
     LuaJIT.lua_newtable(this.luaState);
     LuaJIT.lua_setglobal(this.luaState, "luanet");
     LuaJIT.lua_pushvalue(this.luaState, -10002);
     LuaJIT.lua_getglobal(this.luaState, "luanet");
     LuaJIT.lua_pushstring(this.luaState, "getmetatable");
     LuaJIT.lua_getglobal(this.luaState, "getmetatable");
     LuaJIT.lua_settable(this.luaState, -3);
     LuaJIT.lua_replace(this.luaState, -10002);
     this.translator = new ObjectTranslator(this, this.luaState);
     LuaJIT.lua_replace(this.luaState, -10002);
     LuaJIT.luaL_dostring(this.luaState, init_luanet);
     this.panicCallback = new LuaCSFunction(Lua.PanicCallback);
     LuaJIT.lua_atpanic(this.luaState, this.panicCallback);
 }
예제 #13
0
 public CheckType(ObjectTranslator translator)
 {
     this.translator=translator;
     extractSbyte=new ExtractValue(this.getAsSbyte);
     extractByte=new ExtractValue(this.getAsByte);
     extractShort=new ExtractValue(this.getAsShort);
     extractUshort=new ExtractValue(this.getAsUshort);
     extractInt=new ExtractValue(this.getAsInt);
     extractUint=new ExtractValue(this.getAsUint);
     extractLong=new ExtractValue(this.getAsLong);
     extractUlong=new ExtractValue(this.getAsUlong);
     extractDouble=new ExtractValue(this.getAsDouble);
     extractChar=new ExtractValue(this.getAsChar);
     extractFloat=new ExtractValue(this.getAsFloat);
     extractDecimal=new ExtractValue(this.getAsDecimal);
     extractBoolean=new ExtractValue(this.getAsBoolean);
     extractString=new ExtractValue(this.getAsString);
     extractFunction=new ExtractValue(this.getAsFunction);
     extractTable=new ExtractValue(this.getAsTable);
     extractUserdata=new ExtractValue(this.getAsUserdata);
     extractObject=new ExtractValue(this.getAsObject);
 }
예제 #14
0
 public CheckType(ObjectTranslator translator)
 {
     this.translator  = translator;
     extractSbyte     = new ExtractValue(this.getAsSbyte);
     extractByte      = new ExtractValue(this.getAsByte);
     extractShort     = new ExtractValue(this.getAsShort);
     extractUshort    = new ExtractValue(this.getAsUshort);
     extractInt       = new ExtractValue(this.getAsInt);
     extractUint      = new ExtractValue(this.getAsUint);
     extractLong      = new ExtractValue(this.getAsLong);
     extractUlong     = new ExtractValue(this.getAsUlong);
     extractDouble    = new ExtractValue(this.getAsDouble);
     extractChar      = new ExtractValue(this.getAsChar);
     extractFloat     = new ExtractValue(this.getAsFloat);
     extractDecimal   = new ExtractValue(this.getAsDecimal);
     extractBoolean   = new ExtractValue(this.getAsBoolean);
     extractString    = new ExtractValue(this.getAsString);
     extractFunction  = new ExtractValue(this.getAsFunction);
     extractTable     = new ExtractValue(this.getAsTable);
     extractUserdata  = new ExtractValue(this.getAsUserdata);
     extractObject    = new ExtractValue(this.getAsObject);
     extractNetObject = new ExtractValue(this.getAsNetObject);
 }
예제 #15
0
        public static int loadAssembly(IntPtr luaState)
        {
            ObjectTranslator translator = ObjectTranslator.FromState(luaState);
            try
            {
                string assemblyName = LuaDLL.lua_tostring(luaState, 1);

                Assembly assembly = null;

                //assembly = Assembly.GetExecutingAssembly();

                try
                {
                    assembly = Assembly.Load(assemblyName);
                }
                catch (BadImageFormatException)
                {
                    // The assemblyName was invalid.  It is most likely a path.
                }

                if (assembly == null)
                {
                    assembly = Assembly.Load(AssemblyName.GetAssemblyName(assemblyName));
                }

                if (assembly != null && !translator.assemblies.Contains(assembly))
                {
                    translator.assemblies.Add(assembly);
                }
            }
            catch (Exception e)
            {
                translator.throwError(luaState, e.Message);
            }

            return 0;
        }
예제 #16
0
        public virtual void Dispose()
        {
            if (translator != null)
            {
                translator.pendingEvents.Dispose();
                translator = null;
            }

            this.Close();
            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();
        }
예제 #17
0
파일: Lua.cs 프로젝트: rumkex/LuaInterface
        /*
            * CAUTION: LuaInterface.Lua instances can't share the same lua state!
            */
        public Lua(LuaCore.lua_State lState)
        {
            LuaLib.lua_pushstring(lState, "LUAINTERFACE LOADED");
            LuaLib.lua_gettable(lState, (int)LuaIndexes.Registry);

            if(LuaLib.lua_toboolean(lState, -1))
            {
                LuaLib.lua_settop(lState, -2);
                throw new LuaException("There is already a LuaInterface.Lua instance associated with this Lua state");
            }
            else
            {
                LuaLib.lua_settop(lState, -2);
                LuaLib.lua_pushstring(lState, "LUAINTERFACE LOADED");
                LuaLib.lua_pushboolean(lState, true);
                LuaLib.lua_settable(lState, (int)LuaIndexes.Registry);
                luaState = lState;
                LuaLib.lua_pushvalue(lState, (int)LuaIndexes.Globals);
                LuaLib.lua_getglobal(lState, "luanet");
                LuaLib.lua_pushstring(lState, "getmetatable");
                LuaLib.lua_getglobal(lState, "getmetatable");
                LuaLib.lua_settable(lState, -3);
                LuaLib.lua_replace(lState, (int)LuaIndexes.Globals);
                translator = new ObjectTranslator(this, luaState);
                LuaLib.lua_replace(lState, (int)LuaIndexes.Globals);
                LuaLib.luaL_dostring(lState, Lua.init_luanet);	// steffenj: lua_dostring renamed to luaL_dostring
            }

            _StatePassed = true;
        }
예제 #18
0
 public LuaTable(int reference, IntPtr L)
 {
     _Reference   = reference;
     translator   = ObjectTranslator.FromState(L);
     _Interpreter = translator.interpreter;
 }
예제 #19
0
        /*
         * CAUTION: LuaInterface.Lua instances can't share the same lua state!
         */
        public Lua(KopiLua.Lua.lua_State lState)
        {
            //IntPtr lState = new IntPtr(luaState);
            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.Lua instance associated with this Lua state");
            }
            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);
                LuaDLL.luaL_dostring(lState, Lua.init_luanet);	// steffenj: lua_dostring renamed to luaL_dostring
            }

            _StatePassed = true;
        }
예제 #20
0
 /*
  * Constructs the wrapper for a known MethodBase instance
  */
 public LuaMethodWrapper(ObjectTranslator translator, object target, Type targetType, MethodBase method)
 {
     this.translator=translator;
     this.target=target;
     this.targetType=targetType;
     this.method=method;
     this.methodName=method.Name;
     if(method.IsStatic) { bindingType=BindingFlags.Static; }
     else { bindingType=BindingFlags.Instance; }
 }
예제 #21
0
        public LuaState()
        {
            // Create State
			//Creates a new Lua state. 
			//It calls lua_newstate with an allocator based on the standard C realloc function and then sets a panic function (see §4.6) that prints an error message to the standard error output in case of fatal errors.
			//Returns the new state, or NULL if there is a memory allocation error.
            L = LuaDLL.luaL_newstate();

            // Create LuaInterface library
			//Opens all standard Lua libraries into the given state.
            LuaDLL.luaL_openlibs(L);  

            LuaDLL.lua_pushstring(L, "LUAINTERFACE LOADED");
            LuaDLL.lua_pushboolean(L, true);
			//Does the equivalent to t[k] = v, where t is the value at the given index, v is the value at the top of the stack, and k is the value just below the top.
			//This function pops both the key and the value from the stack. As in Lua, this function may trigger a metamethod for the "newindex" event (see §2.4).
            LuaDLL.lua_settable(L, (int)LuaIndexes.LUA_REGISTRYINDEX);   

            LuaDLL.lua_newtable(L);            
            LuaDLL.lua_setglobal(L, "luanet");
            LuaDLL.lua_pushvalue(L, (int)LuaIndexes.LUA_GLOBALSINDEX);  //压入了_G表
            LuaDLL.lua_getglobal(L, "luanet");
            LuaDLL.lua_pushstring(L, "getmetatable");
            LuaDLL.lua_getglobal(L, "getmetatable");
            LuaDLL.lua_settable(L, -3);
            LuaDLL.lua_pushstring(L, "rawget");
            LuaDLL.lua_getglobal(L, "rawget");
            LuaDLL.lua_settable(L, -3);
            LuaDLL.lua_pushstring(L, "rawset");
            LuaDLL.lua_getglobal(L, "rawset");
            LuaDLL.lua_settable(L, -3);

            // Set luanet as global for object translator                          
            LuaDLL.lua_replace(L, (int)LuaIndexes.LUA_GLOBALSINDEX); //用luanet替换_G表           
            translator = new ObjectTranslator(this, L);            
            LuaDLL.lua_replace(L, (int)LuaIndexes.LUA_GLOBALSINDEX); //恢复_G表                    

            translator.PushTranslator(L);                      

            // We need to keep this in a managed reference so the delegate doesn't get garbage collected
            panicCallback = new LuaCSFunction(LuaStatic.panic);
            LuaDLL.lua_atpanic(L, panicCallback);

            printFunction = new LuaCSFunction(LuaStatic.print);
            LuaDLL.lua_pushstdcallcfunction(L, printFunction);
            LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "print");

            loadfileFunction = new LuaCSFunction(LuaStatic.loadfile);
            LuaDLL.lua_pushstdcallcfunction(L, loadfileFunction);
            LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "loadfile");

            dofileFunction = new LuaCSFunction(LuaStatic.dofile);
            LuaDLL.lua_pushstdcallcfunction(L, dofileFunction);
            LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "dofile");

            // Insert our loader FIRST
            loaderFunction = new LuaCSFunction(LuaStatic.loader);
            LuaDLL.lua_pushstdcallcfunction(L, loaderFunction);
            int loaderFunc = LuaDLL.lua_gettop(L);

            LuaDLL.lua_getfield(L, LuaIndexes.LUA_GLOBALSINDEX, "package");
            LuaDLL.lua_getfield(L, -1, "loaders");
            int loaderTable = LuaDLL.lua_gettop(L);

            // Shift table elements right
            for (int e = LuaDLL.luaL_getn(L, loaderTable) + 1; e > 1; e--)
            {
                LuaDLL.lua_rawgeti(L, loaderTable, e - 1);
                LuaDLL.lua_rawseti(L, loaderTable, e);
            }
            LuaDLL.lua_pushvalue(L, loaderFunc);
            LuaDLL.lua_rawseti(L, loaderTable, 1);
            LuaDLL.lua_settop(L, 0);

            DoString(LuaStatic.init_luanet);
            tracebackFunction = new LuaCSFunction(LuaStatic.traceback);
        }
예제 #22
0
 public Lua(IntPtr _luaState)
 {
     luaState = _luaState;
     translator=new ObjectTranslator(this,luaState);
 }
예제 #23
0
        public void Dispose()
        {
            if (translator != null)
            {
                translator.pendingEvents.Dispose();

                translator = null;
            }
        }
 public DelegateGenerator(ObjectTranslator translator,Type delegateType)
 {
     this.translator=translator;
     this.delegateType=delegateType;
 }
예제 #25
0
 /*
  * Constructs the wrapper for a known method name
  */
 public LuaMethodWrapper(ObjectTranslator translator, Type targetType, string methodName, BindingFlags bindingType)
 {
     this.translator=translator;
     this.methodName=methodName;
     this.targetType=targetType;
     this.bindingType=bindingType;
     members=targetType.GetMember(methodName,MemberTypes.Method,bindingType|BindingFlags.Public|BindingFlags.NonPublic);
 }
 public ClassGenerator(ObjectTranslator translator,Type klass)
 {
     this.translator=translator;
     this.klass=klass;
 }
예제 #27
0
 public ClassGenerator(ObjectTranslator translator, Type klass)
 {
     this.translator = translator;
     this.klass      = klass;
 }
예제 #28
0
파일: Lua.cs 프로젝트: fengqk/Art
        public LuaState()
        {
            // Create State
            L = LuaDLL.luaL_newstate();

            // Create LuaInterface library
            LuaDLL.luaL_openlibs(L);
            LuaDLL.lua_pushstring(L, "LUAINTERFACE LOADED");
            LuaDLL.lua_pushboolean(L, true);
            LuaDLL.lua_settable(L, (int)LuaIndexes.LUA_REGISTRYINDEX);

            tracebackFunction = new LuaCSFunction(LuaStatic.traceback);

            translator = new ObjectTranslator(this, L);
			GCHandle handle = GCHandle.Alloc(translator, GCHandleType.Pinned);
			IntPtr thisptr = GCHandle.ToIntPtr(handle);
			LuaDLL.lua_pushlightuserdata(L, thisptr);
			LuaDLL.lua_setglobal(L, "_translator");

            panicCallback = new LuaCSFunction(LuaStatic.panic);
            LuaDLL.lua_atpanic(L, panicCallback);

            warnFunction = new LuaCSFunction(LuaStatic.warn);
            LuaDLL.lua_pushstdcallcfunction(L, warnFunction);
            LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "warn");

            printFunction = new LuaCSFunction(LuaStatic.print);
            LuaDLL.lua_pushstdcallcfunction(L, printFunction);
            LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "print");

            pcallFunction = new LuaCSFunction(LuaStatic.pcall);
            LuaDLL.lua_pushstdcallcfunction(L, pcallFunction);
            LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "pcall");


            loadfileFunction = new LuaCSFunction(LuaStatic.loadfile);
            LuaDLL.lua_pushstdcallcfunction(L, loadfileFunction);
            LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "loadfile");

            dofileFunction = new LuaCSFunction(LuaStatic.dofile);
            LuaDLL.lua_pushstdcallcfunction(L, dofileFunction);
            LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "dofile");

			LuaDLL.lua_pushstdcallcfunction(L, LuaStatic.errorFunc_traceback);
			errorFuncRef = LuaDLL.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);

			if (LuaStatic.loadbuffer(L, mtindex2, "mtindex2") != 0 || LuaDLL.lua_pcall(L, 0, -1, 0) != 0)
			{
				Debug.Log("Init mtindex error");
				return;
			}

			Debug_funcs = new LuaL_Reg[] 
			{ 
				new LuaL_Reg("GetObjectCount",new  LuaCSFunction(LuaStatic.Debug_GetObjectCount)),
				new LuaL_Reg("LogError",new  LuaCSFunction(LuaStatic.Debug_LogError)),
				new LuaL_Reg("LogWarning",new  LuaCSFunction(LuaStatic.Debug_LogWarning)),
			};
			LuaL_Reg.LuaL_SetFuncs(L, "Debug",Debug_funcs);

			//Vector3_funcs = new LuaL_Reg[] 
			//{ 
			//	new LuaL_Reg("__add",new  LuaCSFunction(LuaStatic.Vector3_add)),
			//	new LuaL_Reg("__sub",new  LuaCSFunction(LuaStatic.Vector3_sub)),
			//	new LuaL_Reg("__mul",new  LuaCSFunction(LuaStatic.Vector3_mul)),
			//	new LuaL_Reg("__div",new  LuaCSFunction(LuaStatic.Vector3_div)),
			//	new LuaL_Reg("__eq",new  LuaCSFunction(LuaStatic.Vector3_eq)),
			//	new LuaL_Reg("__tostring",new  LuaCSFunction(LuaStatic.Vector3_tostring)),
			//};
			//LuaL_Reg.LuaL_SetFuncs(L, "Vector3", Vector3_funcs);


			//-------------------------------------------------------------
            // Insert our loader FIRST
            loaderFunction = new LuaCSFunction(LuaStatic.loader);
            LuaDLL.lua_pushstdcallcfunction(L, loaderFunction);
            int loaderFunc = LuaDLL.lua_gettop(L);


            LuaDLL.lua_getfield(L, LuaIndexes.LUA_GLOBALSINDEX, "package");
            LuaDLL.lua_getfield(L, -1, "loaders");
            int loaderTable = LuaDLL.lua_gettop(L);

            // Shift table elements right
            for (int e = LuaDLL.luaL_getn(L, loaderTable) + 1; e > 1; e--)
            {
                LuaDLL.lua_rawgeti(L, loaderTable, e - 1);
                LuaDLL.lua_rawseti(L, loaderTable, e);
            }
            LuaDLL.lua_pushvalue(L, loaderFunc);
            LuaDLL.lua_rawseti(L, loaderTable, 1);
            LuaDLL.lua_settop(L, 0);

			//LuaStatic.InitObjsWeakTable(L);
		}
예제 #29
0
        public LuaState()
        {
            // Create State
            L = LuaDLL.luaL_newstate();

            // Create LuaInterface library
            LuaDLL.luaL_openlibs(L);
            LuaDLL.lua_pushstring(L, "LUAINTERFACE LOADED");
            LuaDLL.lua_pushboolean(L, true);
            LuaDLL.lua_settable(L, (int) LuaIndexes.LUA_REGISTRYINDEX);
            LuaDLL.lua_newtable(L);
            LuaDLL.lua_setglobal(L, "luanet");
            LuaDLL.lua_pushvalue(L, (int)LuaIndexes.LUA_GLOBALSINDEX);
            LuaDLL.lua_getglobal(L, "luanet");
            LuaDLL.lua_pushstring(L, "getmetatable");
            LuaDLL.lua_getglobal(L, "getmetatable");
            LuaDLL.lua_settable(L, -3);

            // Set luanet as global for object translator
            LuaDLL.lua_replace(L, (int)LuaIndexes.LUA_GLOBALSINDEX);
            translator = new ObjectTranslator(this,L);
            LuaDLL.lua_replace(L, (int)LuaIndexes.LUA_GLOBALSINDEX);

            translator.PushTranslator(L);
            //GCHandle handle = GCHandle.Alloc(translator, GCHandleType.Pinned);
            //IntPtr thisptr = GCHandle.ToIntPtr(handle);
            //LuaDLL.lua_pushlightuserdata(L, thisptr);
            //LuaDLL.lua_setglobal(L, "_translator");            

            // We need to keep this in a managed reference so the delegate doesn't get garbage collected
			panicCallback = new LuaCSFunction(LuaStatic.panic);
            LuaDLL.lua_atpanic(L, panicCallback);

            printFunction = new LuaCSFunction(LuaStatic.print);
            LuaDLL.lua_pushstdcallcfunction(L, printFunction);
            LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "print");

            loadfileFunction = new LuaCSFunction(LuaStatic.loadfile);
            LuaDLL.lua_pushstdcallcfunction(L, loadfileFunction);
            LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "loadfile");

            dofileFunction = new LuaCSFunction(LuaStatic.dofile);
            LuaDLL.lua_pushstdcallcfunction(L, dofileFunction);
            LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "dofile");

            // Insert our loader FIRST
            loaderFunction = new LuaCSFunction(LuaStatic.loader);
            LuaDLL.lua_pushstdcallcfunction(L, loaderFunction);
            int loaderFunc = LuaDLL.lua_gettop( L );

            LuaDLL.lua_getfield( L, LuaIndexes.LUA_GLOBALSINDEX, "package" );
            LuaDLL.lua_getfield( L, -1, "loaders" );
            int loaderTable = LuaDLL.lua_gettop( L );

            // Shift table elements right
            for( int e = LuaDLL.luaL_getn( L, loaderTable ) + 1; e > 1; e-- ) 
            {
                LuaDLL.lua_rawgeti( L, loaderTable, e-1 );
                LuaDLL.lua_rawseti( L, loaderTable, e );
            }
            LuaDLL.lua_pushvalue( L, loaderFunc );
            LuaDLL.lua_rawseti( L, loaderTable, 1 );
            LuaDLL.lua_settop( L, 0 );

            DoString(LuaStatic.init_luanet);            
            tracebackFunction = new LuaCSFunction(LuaStatic.traceback);
        }
예제 #30
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*/);
        }
예제 #31
0
파일: Lua.cs 프로젝트: rumkex/LuaInterface
        public virtual void Dispose()
        {
            if(!translator.IsNull())
            {
                translator.pendingEvents.Dispose();
                translator = null;
            }

            this.Close();
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
예제 #32
0
 public DelegateGenerator(ObjectTranslator translator, Type delegateType)
 {
     this.translator   = translator;
     this.delegateType = delegateType;
 }
예제 #33
0
		public virtual void Dispose(bool dispose)
		{
			if( dispose )
			{
			    if (translator != null)
	            {
	                translator.pendingEvents.Dispose();
	                translator = null;
	            }	
			}
		}
예제 #34
0
파일: Lua.cs 프로젝트: viticm/pap2
        public void Dispose()
        {
            if (translator != null)
            {
                foreach (LuaTable t in luaTables)
                {
                    dispose(t.reference);
                }
                luaTables.Clear();

                foreach (LuaFunction f in luaFunctions)
                {
                    dispose(f.reference);
                }
                luaFunctions.Clear();

                translator.pendingEvents.Dispose();
                translator = null;
            }
        }