예제 #1
0
    public static int _bind_setAlphaMovie(Lua.lua_State L)
    {
        if (Lua.lua_gettop(L) != 3 ||
            Luna.get_uniqueid(L, 1) != 7105034 ||
            Lua.lua_isstring(L, 2) == 0 ||
            Lua.lua_isnumber(L, 3) == 0)
        {
            Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed:setAlphaMovie(LWF.LWF self)");
        }

        LWF.LWF self         = Luna_LWF_LWF.check(L, 1);
        string  instanceName = Lua.lua_tostring(L, 2).ToString();
        float   v            = (float)Lua.lua_tonumber(L, 3);

        try {
            self.SetAlphaMovie(instanceName, v);
        } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); }
        return(0);
    }
예제 #2
0
    public static int _bind_setVisibleMovie(Lua.lua_State L)
    {
        if (Lua.lua_gettop(L) != 3 ||
            Luna.get_uniqueid(L, 1) != 7105034 ||
            Lua.lua_isstring(L, 2) == 0 ||
            !Lua.lua_isboolean(L, 3))
        {
            Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed:setVisibleMovie(LWF.LWF self)");
        }

        LWF.LWF self         = Luna_LWF_LWF.check(L, 1);
        string  instanceName = Lua.lua_tostring(L, 2).ToString();
        bool    visible      = (Lua.lua_toboolean(L, 3) != 0);

        try {
            self.SetVisibleMovie(instanceName, visible);
        } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); }
        return(0);
    }
예제 #3
0
    public static int _bind_setText(Lua.lua_State L)
    {
        if (Lua.lua_gettop(L) != 3 ||
            Luna.get_uniqueid(L, 1) != 7105034 ||
            Lua.lua_isstring(L, 2) == 0 ||
            Lua.lua_isstring(L, 3) == 0)
        {
            Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed:setText(LWF.LWF self)");
        }

        LWF.LWF self     = Luna_LWF_LWF.check(L, 1);
        string  textName = Lua.lua_tostring(L, 2).ToString();
        string  text     = Lua.lua_tostring(L, 3).ToString();

        try {
            self.SetText(textName, text);
        } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); }
        return(0);
    }
예제 #4
0
    public static int _bind_removeButtonEventListener(Lua.lua_State L)
    {
        if (Lua.lua_gettop(L) != 3 ||
            Luna.get_uniqueid(L, 1) != 7105034 ||
            Lua.lua_isstring(L, 2) == 0 ||
            Lua.lua_isnumber(L, 3) == 0)
        {
            Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed:removeButtonEventListener(LWF.LWF self)");
        }

        LWF.LWF self         = Luna_LWF_LWF.check(L, 1);
        string  instanceName = Lua.lua_tostring(L, 2).ToString();
        int     id           = (int)Lua.lua_tonumber(L, 3);

        try {
            self.RemoveButtonEventHandler(instanceName, id);
        } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); }
        return(0);
    }
예제 #5
0
        public int Lua_MsgBox(Lua.lua_State m_lua_state)
        {
            string text = String.Empty;

            if (Lua.lua_type(m_lua_state, -1) == Lua.LUA_TSTRING)
            {
                text = Lua.lua_tostring(m_lua_state, -1).ToString();
                Lua.lua_pop(m_lua_state, 1);
                Lua.lua_pushboolean(m_lua_state, MsgBox(text));
                return(1);
            }
            else
            {
                Lua.lua_settop(m_lua_state, 0);
            }

            Lua.lua_pushstring(m_lua_state, "invalid argument to function: msgbox(string text)");
            return(Lua.lua_error(m_lua_state));
        }
예제 #6
0
 static public LWF.Point check(Lua.lua_State L, int narg)
 {
     byte[] d = (byte[])Lua.lua_touserdata(L, narg);
     if (d == null)
     {
         Luna.print("checkRaw: ud==nil\n"); Lua.luaL_typerror(L, narg, LunaTraits_LWF_Point.className);
     }
     Luna.userdataType ud = new Luna.userdataType(d);
     if (ud.TypeId != LunaTraits_LWF_Point.uniqueID)       // type checking with almost no overhead
     {
         Luna.print(String.Format("ud.uid: {0} != interface::uid : {1}\n", ud.TypeId, LunaTraits_LWF_Point.uniqueID));
         Lua.luaL_typerror(L, narg, LunaTraits_LWF_Point.className);
     }
     LWF.Point obj = null;
     if (!objects[L].TryGetValue(ud.ObjectId, out obj))
     {
         return(null);
     }
     return(obj);
 }
예제 #7
0
    public static int _bind_gotoAndPlayMovie(Lua.lua_State L)
    {
        if (Lua.lua_gettop(L) == 3 &&
            Luna.get_uniqueid(L, 1) == 7105034 &&
            Lua.lua_isstring(L, 2) == 1 &&
            Lua.lua_isnumber(L, 3) == 1)
        {
            return(_bind_gotoAndPlayMovie_overload_1(L));
        }
        if (Lua.lua_gettop(L) == 3 &&
            Luna.get_uniqueid(L, 1) == 7105034 &&
            Lua.lua_isstring(L, 2) == 1 &&
            Lua.lua_isstring(L, 3) == 1)
        {
            return(_bind_gotoAndPlayMovie_overload_2(L));
        }
        Lua.luaL_error(L, "gotoAndPlayMovie cannot find overloads.");

        return(0);
    }
예제 #8
0
        static int getargs(Lua.lua_State L, string[] argv, int n)
        {
            int narg;
            int i;
            int argc = argv.Length;             /* count total number of arguments */

            narg = argc - (n + 1);              /* number of arguments to the script */
            Lua.luaL_checkstack(L, narg + 3, "too many arguments to script");
            for (i = n + 1; i < argc; i++)
            {
                Lua.lua_pushstring(L, argv[i]);
            }
            Lua.lua_createtable(L, narg, n + 1);
            for (i = 0; i < argc; i++)
            {
                Lua.lua_pushstring(L, argv[i]);
                Lua.lua_rawseti(L, -2, i - n);
            }
            return(narg);
        }
예제 #9
0
    // use lunaStack::push if possible.
    public static void push(Lua.lua_State L, LWF.Point obj, bool gc, Lua.CharPtr metatable = null)
    {
        if (obj == null)
        {
            Lua.lua_pushnil(L);
            return;
        }

        int objectId = -1;

        if (!objectIdentifiers[L].TryGetValue(obj, out objectId))
        {
            objectId = idOffset++;
            objectIdentifiers[L].Add(obj, objectId);
            objects[L].Add(objectId, obj);
        }

        if (metatable == null)
        {
            metatable = LunaTraits_LWF_Point.className;
        }
        Lua.lua_pushstring(L, "__luna");
        Lua.lua_gettable(L, Lua.LUA_GLOBALSINDEX);
        int __luna = Lua.lua_gettop(L);

        Luna.userdataType ud = new Luna.userdataType(
            objectId: objectId,  // store object in userdata
            gc: gc,              // collect garbage
            has_env: false,      // does this userdata has a table attached to it?
            typeId: LunaTraits_LWF_Point.uniqueID
            );

        ud.ToBytes((byte[])Lua.lua_newuserdata(L, Luna.userdataType.Size));

        Lua.lua_pushstring(L, metatable);
        Lua.lua_gettable(L, __luna);
        Lua.lua_setmetatable(L, -2);
        //Luna.printStack(L);
        Lua.lua_insert(L, -2);          // swap __luna and userdata
        Lua.lua_pop(L, 1);
    }
예제 #10
0
    public static int __index(Lua.lua_State L)
    {
        {
            Lua.lua_CFunction fnc = null;
            if (LunaTraits_LWF_Point.properties.TryGetValue(Lua.lua_tostring(L, 2).ToString(), out fnc))
            {
                Lua.lua_pop(L, 1);                // remove self
                return(fnc(L));
            }
        }

        int mt = Lua.lua_getmetatable(L, 1);

        if (mt == 0)
        {
            Lua.luaL_error(L, "__index");             //end
        }
        Lua.lua_pushstring(L, Lua.lua_tostring(L, 2));
        Lua.lua_rawget(L, -2);
        return(1);
    }
예제 #11
0
파일: lwf_lua.cs 프로젝트: xubingyue/lwf
        public string GetTextLua(Movie movie, string textName)
        {
            if (luaState == null)
            {
                return("");
            }

            Lua.lua_State l = (Lua.lua_State)luaState;
            if (!GetFieldLua(movie, textName) || Lua.lua_isstring(l, -1) == 0)
            {
                /* -1: nil or not text */
                Lua.lua_pop(l, 1);
                return("");
            }
            /* -1: text */
            string text = Lua.lua_tostring(l, -1).ToString();

            Lua.lua_pop(l, 1);
            /* 0 */
            return(text);
        }
예제 #12
0
파일: luna.cs 프로젝트: xubingyue/lwf
    public static void printStack(Lua.lua_State L, bool compact = false)
    {
        if (compact)
        {
            print(String.Format("stack top:{0} - ", Lua.lua_gettop(L)));
        }
        else
        {
            print(String.Format("stack trace: top {0}\n", Lua.lua_gettop(L)));
        }

        for (int ist = 1; ist <= Lua.lua_gettop(L); ist++)
        {
            if (compact)
            {
                print("" + ist + ":" + Lua.luaL_typename(L, ist)[0]);
            }
            else
            {
                print("" + ist + ":" + Lua.luaL_typename(L, ist).ToString());
            }
            if (Lua.lua_isnumber(L, ist) == 1)
            {
                print("=" + (float)Lua.lua_tonumber(L, ist));
            }
            else if (Lua.lua_isstring(L, ist) == 1)
            {
                print("=" + Lua.lua_tostring(L, ist).ToString());
            }
            else
            {
                print(" ");
            }
            if (!compact)
            {
                print("\n");
            }
        }
        print("\n");
    }
예제 #13
0
        // unwrapped
        // was out strLen
        // public static IntPtr lua_tolstring(Lua.lua_State luaState, int index, [Out] int ^ strLen);

        public static string lua_tostring(Lua.lua_State luaState, int index)
        {
#if true
            // FIXME use the same format string as lua i.e. LUA_NUMBER_FMT
            LuaTypes t = lua_type(luaState, index);

            if (t == LuaTypes.LUA_TNUMBER)
            {
                return(string.Format("{0}", lua_tonumber(luaState, index)));
            }
            else if (t == LuaTypes.LUA_TSTRING)
            {
                uint strlen;
                return(Lua.lua_tolstring(luaState, index, out strlen).ToString());
            }
            else if (t == LuaTypes.LUA_TNIL)
            {
                return(null);                                   // treat lua nulls to as C# nulls
            }
            else
            {
                return("0");                    // Because luaV_tostring does this
            }
#else
            size_t strlen;

            // Note!  This method will _change_ the representation of the object on the stack to a string.
            // We do not want this behavior so we do the conversion ourselves
            const char *str = Lua.lua_tolstring(luaState, index, &strlen);
            if (str)
            {
                return(Marshal::PtrToStringAnsi(IntPtr((char *)str), strlen));
            }
            else
            {
                return(nullptr);            // treat lua nulls to as C# nulls
            }
#endif
        }
예제 #14
0
파일: lwf_lua.cs 프로젝트: xubingyue/lwf
        public void DestroyLua()
        {
            if (luaState == null)
            {
                return;
            }

            Lua.lua_State l = (Lua.lua_State)luaState;
            Lua.lua_getglobal(l, "LWF");
            /* -1: LWF */
            if (!Lua.lua_istable(l, -1))
            {
                Lua.lua_pop(l, 1);
                /* 0 */
                return;
            }
            Lua.lua_getfield(l, -1, "Instances");
            /* -2: LWF */
            /* -1: LWF.Instances */
            Lua.lua_remove(l, -2);
            /* -1: LWF.Instances */
            if (!Lua.lua_istable(l, -1))
            {
                Lua.lua_pop(l, 1);
                /* 0 */
                return;
            }
            Lua.lua_pushnil(l);
            /* -2: LWF.Instances */
            /* -1: nil */
            Lua.lua_setfield(l, -2, instanceIdString);
            /* LWF.Instances.<instanceId> = nil */
            /* -1: LWF.Instances */
            Lua.lua_pop(l, 1);
            /* 0 */
            Luna_LWF_LWF.Destroy(l, this);
            LuaLWF.close(l);
        }
예제 #15
0
    public static int attachMovie(Lua.lua_State L)
    {
        LWF.Movie a;
        int       args = Lua.lua_gettop(L);

        if (args < 3 || args > 6)
        {
            goto error;
        }
        if (Luna.get_uniqueid(L, 1) != LunaTraits_LWF_Movie.uniqueID)
        {
            goto error;
        }
        if (Lua.lua_isstring(L, 2) == 0 || Lua.lua_isstring(L, 3) == 0)
        {
            goto error;
        }
        if (args >= 4 && !Lua.lua_istable(L, 4))
        {
            goto error;
        }
        if (args >= 5 && Lua.lua_isnumber(L, 5) == 0)
        {
            goto error;
        }
        if (args >= 6 && !Lua.lua_isboolean(L, 6))
        {
            goto error;
        }

        a = Luna_LWF_Movie.check(L, 1);
        return(a.lwf.AttachMovieLua(a));

error:
        Luna.printStack(L);
        Lua.luaL_error(L, "luna typecheck failed: LWF.Movie.attachMovie");
        return(1);
    }
예제 #16
0
    // garbage collection metamethod
    private static int gc_T(Lua.lua_State L)
    {
        byte[] d = (byte[])Lua.lua_touserdata(L, 1);
        if (d == null)
        {
            Luna.print("checkRaw: ud==nil\n"); Lua.luaL_typerror(L, 1, LunaTraits_LWF_Point.className);
        }
        Luna.userdataType ud = new Luna.userdataType(d);

        LWF.Point obj = null;
        if (!objects[L].TryGetValue(ud.ObjectId, out obj))
        {
            return(0);
        }

        if (ud.Gc)
        {
            LunaTraits_LWF_Point._bind_dtor(obj);              // call constructor for T objects
            Destroy(L, obj);
        }

        return(0);
    }
예제 #17
0
파일: Utils.cs 프로젝트: DGoodayle/kopilua
        public static void DumpStack(Lua.lua_State L)
        {
            for (int i = -Lua.lua_gettop(L); i < 0; ++i)
            {
                string s = "?";
                int    t = Lua.lua_type(L, i);
                switch (t)
                {
                case Lua.LUA_TSTRING:
                    s = Lua.lua_tostring(L, i).ToString();
                    break;

                case Lua.LUA_TBOOLEAN:
                    s = Lua.lua_toboolean(L, i) != 0 ? "true" : "false";
                    break;

                case Lua.LUA_TNUMBER:
                    s = Lua.lua_tonumber(L, i).ToString();
                    break;
                }
                Debug.WriteLine(string.Format("{0}: {1} {2}", i, Lua.lua_typename(L, t), s));
            }
        }
예제 #18
0
        // unwrapped
        // was out strLen
        // public static IntPtr lua_tolstring(Lua.lua_State luaState, int index, [Out] int ^ strLen);

        public static string lua_tostring(Lua.lua_State luaState, int index)
        {
            // FIXME use the same format string as lua i.e. LUA_NUMBER_FMT
            LuaTypes t = lua_type(luaState, index);

            if (t == LuaTypes.LUA_TNUMBER)
            {
                return(string.Format("{0}", lua_tonumber(luaState, index)));
            }
            else if (t == LuaTypes.LUA_TSTRING)
            {
                uint strlen;
                return(Lua.lua_tolstring(luaState, index, out strlen).ToString());
            }
            else if (t == LuaTypes.LUA_TNIL)
            {
                return(null);                                   // treat lua nulls to as C# nulls
            }
            else
            {
                return("0");                    // Because luaV_tostring does this
            }
        }
예제 #19
0
 static int traceback(Lua.lua_State L)
 {
     if (Lua.lua_isstring(L, 1) == 0) /* 'message' not a string? */
     {
         return(1);                   /* keep it intact */
     }
     Lua.lua_getfield(L, Lua.LUA_GLOBALSINDEX, "debug");
     if (!Lua.lua_istable(L, -1))
     {
         Lua.lua_pop(L, 1);
         return(1);
     }
     Lua.lua_getfield(L, -1, "traceback");
     if (!Lua.lua_isfunction(L, -1))
     {
         Lua.lua_pop(L, 2);
         return(1);
     }
     Lua.lua_pushvalue(L, 1);            /* pass error message */
     Lua.lua_pushinteger(L, 2);          /* skip this function and traceback */
     Lua.lua_call(L, 2, 1);              /* call debug.traceback */
     return(1);
 }
예제 #20
0
    public static int __newindex(Lua.lua_State L)
    {
        Lua.lua_CFunction fnc = null;
        if (LunaTraits_LWF_Movie.write_properties.TryGetValue(Lua.lua_tostring(L, 2).ToString(), out fnc))
        {
            Lua.lua_insert(L, 2);            // swap key and value
            Lua.lua_settop(L, 2);            // delete key
            return(fnc(L));
        }
        if (Lua.lua_gettop(L) == 3 && Luna.get_uniqueid(L, 1) ==
            LunaTraits_LWF_Movie.uniqueID)
        {
            LWF.Movie o =
                Luna_LWF_Movie.check(L, 1);
            string name = Lua.lua_tostring(L, 2).ToString();
            if (o.lwf.SetFieldLua(o, name))
            {
                return(0);
            }
        }

        Lua.luaL_error(L, "__newindex doesn't allow defining non-property member");
        return(0);
    }
예제 #21
0
 public static string luaL_typename(Lua.lua_State luaState, int stackPos)
 {
     return(lua_typename(luaState, lua_type(luaState, stackPos)));
 }
예제 #22
0
 public static string lua_typename(Lua.lua_State luaState, LuaTypes type)
 {
     return(Lua.lua_typename(luaState, (int)type).ToString());
 }
예제 #23
0
        // steffenj: BEGIN additional Lua API functions new in Lua 5.1

        public static int lua_gc(Lua.lua_State luaState, LuaGCOptions what, int data)
        {
            return(Lua.lua_gc(luaState, (int)what, data));
        }
예제 #24
0
 public static void luanet_newudata(Lua.lua_State luaState, int val)
 {
     byte[] userdata = lua_newuserdata(luaState, sizeof(int)) as byte[];
     intToFourBytes(val, userdata);
 }
예제 #25
0
 public static int luanet_rawnetobj(Lua.lua_State luaState, int obj)
 {
     byte[] bytes = lua_touserdata(luaState, obj) as byte[];
     return(fourBytesToInt(bytes));
 }
예제 #26
0
 public static void lua_pushlightuserdata(Lua.lua_State luaState, object udata)
 {
     Lua.lua_pushlightuserdata(luaState, udata);
 }
예제 #27
0
 public static int lua_next(Lua.lua_State luaState, int index)
 {
     return(Lua.lua_next(luaState, index));
 }
예제 #28
0
 public static bool lua_checkstack(Lua.lua_State luaState, int extra)
 {
     return(Lua.lua_checkstack(luaState, extra) != 0);
 }
예제 #29
0
 public static void luaL_error(Lua.lua_State luaState, string message)
 {
     Lua.luaL_error(luaState, message);
 }
예제 #30
0
 public static void luaL_where(Lua.lua_State luaState, int level)
 {
     Lua.luaL_where(luaState, level);
 }
예제 #31
0
파일: lua.cs 프로젝트: chenzuo/SharpLua
 static int pmain(Lua.lua_State L)
 {
     Smain s = (Smain)Lua.lua_touserdata(L, 1);
     string[] argv = s.argv;
     int script;
     int has_i = 0, has_v = 0, has_e = 0;
     globalL = L;
     if ((argv.Length > 0) && (argv[0] != "")) progname = argv[0];
     Lua.lua_gc(L, Lua.LUA_GCSTOP, 0);  /* stop collector during initialization */
     Lua.luaL_openlibs(L);  /* open libraries */
     Lua.lua_gc(L, Lua.LUA_GCRESTART, 0);
     s.status = handle_luainit(L);
     if (s.status != 0) return 0;
     script = collectargs(argv, ref has_i, ref has_v, ref has_e);
     if (script < 0)
     {  /* invalid args? */
         print_usage();
         s.status = 1;
         return 0;
     }
     if (has_v != 0) print_version();
     s.status = runargs(L, argv, (script > 0) ? script : s.argc);
     if (s.status != 0) return 0;
     if (script != 0)
         s.status = handle_script(L, argv, script);
     if (s.status != 0) return 0;
     if (has_i != 0)
         dotty(L);
     else if ((script == 0) && (has_e == 0) && (has_v == 0))
     {
         if (Lua.lua_stdin_is_tty() != 0)
         {
             print_version();
             dotty(L);
         }
         else dofile(L, null);  /* executes stdin as a file */
     }
     return 0;
 }