示例#1
0
        /// <summary>[-0, +1, e] Pushes the object into the Lua stack according to its type.</summary>
        internal void push(lua.State L, object o)
        {
            Debug.Assert(interpreter.IsSameLua(L));
            if (o == null)
            {
                lua.pushnil(L);
                return;
            }
            var conv = o as IConvertible;

            if (conv != null && conv is Enum == false)
            {
                switch (conv.GetTypeCode())
                {
                case TypeCode.Boolean: lua.pushboolean(L, (bool)conv);       return;

                case TypeCode.Double:  lua.pushnumber(L, (double)conv);       return;

                case TypeCode.Single:  lua.pushnumber(L, (float)conv);       return;

                case TypeCode.String:  lua.pushstring(L, (string)conv);       return;

                case TypeCode.Char:    lua.pushnumber(L, (char)conv);       return;

                // all the integer types and System.Decimal
                default:               lua.pushnumber(L, conv.ToDouble(null)); return;

                case TypeCode.Empty:
                case TypeCode.DBNull:  lua.pushnil(L);                      return;

                case TypeCode.Object:
                case TypeCode.DateTime: break;
                }
            }

                        #if !__NOGEN__
            { var x = AsILua(o);
              if (x != null)
              {
                  var t = x.__luaInterface_getLuaTable();
                  if (t.Owner != interpreter)
                  {
                      throw Lua.NewCrossInterpreterError(t);
                  }
                  t.push(L); return;
              }
            }
                        #endif
            { var x = o as LuaBase;
              if (x != null)
              {
                  if (x.Owner != interpreter)
                  {
                      throw Lua.NewCrossInterpreterError(x);
                  }
                  x.push(L); return;
              }
            }

            { var x = o as lua.CFunction;
              if (x != null)
              {
                  luaclr.pushcfunction(L, x); return;
              }
            }

            if (o is LuaValue)
            {
                ((LuaValue)o).push(L); return;
            }

            // disallow all reflection
            if ((o.GetType().Namespace ?? "").StartsWith("System.Reflect", StringComparison.Ordinal))
            {
                lua.pushstring(L, o.ToString());
                return;
            }

            pushObject(L, o);
        }