/// <summary>[-0, +0, m, requires checkstack(1)] Add CLR object instance metatable entries to a new ref metatable at the top of the stack.</summary> public void BuildObjectMetatable(lua.State L) { Debug.Assert(interpreter.IsSameLua(L) && luaclr.isrefmeta(L, -1)); lua.newtable(L); lua.setfield(L, -2, "cache"); lua.pushcfunction(L, _index); lua.setfield(L, -2, "__index"); lua.pushcfunction(L, _toString); lua.setfield(L, -2, "__tostring"); lua.pushcfunction(L, _newindex); lua.setfield(L, -2, "__newindex"); }
protected LuaBase(lua.State L, Lua interpreter) { Debug.Assert(interpreter != null && interpreter.IsSameLua(L)); var actual = lua.type(L, -1); if (actual != this.Type) { luaL.error(L, FormatTypeError(actual)); } this.Reference = luaL.@ref(L); this.Owner = interpreter; }
protected LuaBase(lua.State L, Lua interpreter, int index) { Debug.Assert(interpreter != null && interpreter.IsSameLua(L)); var actual = lua.type(L, index); if (actual != this.Type) { luaL.error(L, FormatTypeError(actual)); } luaL.checkstack(L, 1, "LuaBase.ctor(lua.State,Lua,int)"); lua.pushvalue(L, index); this.Reference = luaL.@ref(L); this.Owner = interpreter; }
void luanet.IPushable.push(lua.State L) { if (this.IsDisposed) { luaL.error(L, "Attempted to use a disposed {0}.", this.GetType().Name); } else if (!_interpreter.IsSameLua(L)) { luaL.error(L, this.CrossInterpreterError()); } else { this.push(L); } }
/// <summary>[-0, +0, v] Convert <paramref name="ex"/> to a Lua error. This function never returns.</summary> internal int throwError(lua.State L, Exception ex) { Debug.Assert(interpreter.IsSameLua(L)); Debug.Assert(ex != null); Debug.Assert(ex is LuaInternalException == false); if (ex is OutOfMemoryException) { luaclr.errormemory(L); } // Determine the position in the script where the exception was triggered // Stack frame #0 is our C# wrapper, so not very interesting to the user // Stack frame #1 must be the lua code that called us, so that's what we want to use string errLocation = luanet.where (L, 1); // Wrap generic .NET exception as an InnerException and store the error location ex = new LuaScriptException(ex, errLocation); // don't need to check the stack, same pattern as luaL_error push(L, ex); return(lua.error(L)); }
public ObjectTranslator(lua.State L, Lua interpreter) { Debug.Assert(interpreter.IsSameLua(L)); luaclr.checkstack(L, 1, "new ObjectTranslator"); this.interpreter = interpreter; typeChecker = new CheckType(interpreter); metaFunctions = new MetaFunctions(L, this); StackAssert.Start(L); lua.pushcfunction(L, _loadAssembly = this.loadAssembly); lua.setglobal(L, "load_assembly"); lua.pushcfunction(L, _importType = this.importType); lua.setglobal(L, "import_type"); lua.pushcfunction(L, _makeObject = this.makeObject); lua.setglobal(L, "make_object"); lua.pushcfunction(L, _freeObject = this.freeObject); lua.setglobal(L, "free_object"); lua.pushcfunction(L, _getMethodBysig = this.getMethodBysig); lua.setglobal(L, "get_method_bysig"); lua.pushcfunction(L, _getConstructorBysig = this.getConstructorBysig); lua.setglobal(L, "get_constructor_bysig"); lua.pushcfunction(L, _ctype = this.ctype); lua.setglobal(L, "ctype"); lua.pushcfunction(L, _enum = this.@enum); lua.setglobal(L, "enum"); StackAssert.End(); }
public object extractGenerated(lua.State L, int index) { Debug.Assert(interpreter.IsSameLua(L)); return(CodeGeneration.Instance.GetClassInstance(klass, new LuaTable(L, interpreter, index))); }
public object extractGenerated(lua.State L, int index) { Debug.Assert(interpreter.IsSameLua(L)); return(CodeGeneration.Instance.GetDelegate(delegateType, new LuaFunction(L, interpreter, index))); }
/// <summary>[-0, +0, m] Checks if the value at the specified Lua stack index matches paramType, returning a conversion function if it does and null otherwise.</summary> /// <exception cref="NullReferenceException"><paramref name="paramType"/> is required</exception> internal ExtractValue checkType(lua.State L, int index, Type paramType) { Debug.Assert(interpreter.IsSameLua(L)); Debug.Assert(paramType != null); if (paramType.IsByRef) { paramType = paramType.GetElementType(); } Debug.Assert(paramType != null); Type underlyingType = Nullable.GetUnderlyingType(paramType); if (underlyingType != null) { paramType = underlyingType; // Silently convert nullable types to their non null requics } Caster caster; if (_casters.TryGetValue(paramType.TypeHandle, out caster)) { return(caster.CheckValue(L, index) ? caster.ExtractValue : null); } switch (lua.type(L, index)) { case LUA.T.FUNCTION: if (typeof(Delegate).IsAssignableFrom(paramType)) { #if __NOGEN__ luaL.error(L, "Delegates not implemented"); #else return(new ExtractValue(new DelegateGenerator(interpreter, paramType).extractGenerated)); #endif } break; case LUA.T.TABLE: if (paramType.IsInterface) { #if __NOGEN__ luaL.error(L, "Interfaces not implemented"); #else return(new ExtractValue(new ClassGenerator(interpreter, paramType).extractGenerated)); #endif } luaL.checkstack(L, 1, "CheckType.checkType"); if (luaL.getmetafield(L, index, "__index")) { object indexer = luaclr.toref(L, -1); lua.pop(L, 1); if (paramType.IsInstanceOfType(indexer)) { return(extractNetObject); } } break; case LUA.T.NIL: if (paramType.IsClass || paramType.IsInterface) { return(extractNetObject); } break; case LUA.T.USERDATA: object obj = luaclr.toref(L, index); if (paramType.IsInstanceOfType(obj)) { return(extractNetObject); } break; } return(null); }