コード例 #1
0
        /// <summary>
        /// Returns table, containing information about the current date/time.
        /// </summary>
        /// <remarks>
        /// Result:
        /// {
        ///		integer year,     -- Current year
        ///		integer month,    -- Current month
        ///		integer day,      -- Current day
        ///		integer weekday,  -- Day of the week (0-6), starting on Sunday
        ///		integer yearday,  -- Day of the current year
        ///		integer hour,     -- Current hours (0-23)
        ///		integer min,      -- Current minutes (0-59)
        ///		integer sec,      -- Current seconds (0-59)
        ///		integer msec,     -- Current milliseconds (0-999)
        ///		boolean isdst,    -- Is Daylight Saving Time?
        ///		integer unixts,   -- Unix timestamp
        /// }
        /// </remarks>
        /// <param name="L"></param>
        /// <returns></returns>
        private int gettime(IntPtr L)
        {
            var now = DateTime.Now;

            // TODO: Could a general table generation like this be cached?

            Melua.lua_newtable(L);

            Melua.lua_pushstring(L, "year");
            Melua.lua_pushinteger(L, now.Year);
            Melua.lua_settable(L, -3);

            Melua.lua_pushstring(L, "month");
            Melua.lua_pushinteger(L, now.Month);
            Melua.lua_settable(L, -3);

            Melua.lua_pushstring(L, "day");
            Melua.lua_pushinteger(L, now.Day);
            Melua.lua_settable(L, -3);

            Melua.lua_pushstring(L, "weekday");
            Melua.lua_pushinteger(L, (int)now.DayOfWeek);
            Melua.lua_settable(L, -3);

            Melua.lua_pushstring(L, "yearday");
            Melua.lua_pushinteger(L, now.DayOfYear);
            Melua.lua_settable(L, -3);

            Melua.lua_pushstring(L, "hour");
            Melua.lua_pushinteger(L, now.Hour);
            Melua.lua_settable(L, -3);

            Melua.lua_pushstring(L, "min");
            Melua.lua_pushinteger(L, now.Minute);
            Melua.lua_settable(L, -3);

            Melua.lua_pushstring(L, "sec");
            Melua.lua_pushinteger(L, now.Second);
            Melua.lua_settable(L, -3);

            Melua.lua_pushstring(L, "msec");
            Melua.lua_pushinteger(L, now.Millisecond);
            Melua.lua_settable(L, -3);

            Melua.lua_pushstring(L, "isdst");
            Melua.lua_pushboolean(L, now.IsDaylightSavingTime());
            Melua.lua_settable(L, -3);

            Melua.lua_pushstring(L, "unixts");
            Melua.lua_pushinteger(L, (int)(now.ToUniversalTime().Subtract(UnixEpoch)).TotalSeconds);
            Melua.lua_settable(L, -3);

            return(1);
        }
コード例 #2
0
ファイル: Melua.cs プロジェクト: xyfc/Melua
        public void typename()
        {
            var L = Melua.luaL_newstate();

            Melua.lua_pushinteger(L, 123);
            Assert.Equal("number", Melua.luaL_typename(L, -1));

            Melua.lua_pushstring(L, "123");
            Assert.Equal("string", Melua.luaL_typename(L, -1));

            Melua.lua_newtable(L);
            Assert.Equal("table", Melua.luaL_typename(L, -1));
        }
コード例 #3
0
ファイル: Melua.cs プロジェクト: xyfc/Melua
        public void type()
        {
            var L = Melua.luaL_newstate();

            Melua.lua_pushinteger(L, 123);
            Assert.Equal(Melua.LUA_TNUMBER, Melua.lua_type(L, -1));

            Melua.lua_pushstring(L, "123");
            Assert.Equal(Melua.LUA_TSTRING, Melua.lua_type(L, -1));

            Melua.lua_newtable(L);
            Assert.Equal(Melua.LUA_TTABLE, Melua.lua_type(L, -1));
        }
コード例 #4
0
        /// <summary>
        /// Returns a table with information about the player.
        /// </summary>
        /// <remarks>
        /// Result:
        /// {
        ///		string  name,     -- Character's name
        ///		string  teamName, -- Character's team name
        ///		integer gender,   -- Character's gender
        ///		integer level,    -- Character's level
        ///		integer hp,       -- Character's HP
        ///		integer maxHp,    -- Character's max HP
        ///		integer sp,       -- Character's SP
        ///		integer maxSp,    -- Character's max SP
        ///		integer stamina,  -- Character's stamina
        ///		integer hair,     -- Character's hair
        /// }
        /// </remarks>
        /// <param name="L"></param>
        /// <returns></returns>
        private int getpc(IntPtr L)
        {
            var conn      = this.GetConnectionFromState(L);
            var character = conn.SelectedCharacter;

            Melua.lua_newtable(L);

            Melua.lua_pushstring(L, "name");
            Melua.lua_pushstring(L, character.Name);
            Melua.lua_settable(L, -3);

            Melua.lua_pushstring(L, "teamName");
            Melua.lua_pushstring(L, character.TeamName);
            Melua.lua_settable(L, -3);

            Melua.lua_pushstring(L, "gender");
            Melua.lua_pushinteger(L, (int)character.Gender);
            Melua.lua_settable(L, -3);

            Melua.lua_pushstring(L, "level");
            Melua.lua_pushinteger(L, character.Level);
            Melua.lua_settable(L, -3);

            Melua.lua_pushstring(L, "hp");
            Melua.lua_pushinteger(L, character.Hp);
            Melua.lua_settable(L, -3);

            Melua.lua_pushstring(L, "maxHp");
            Melua.lua_pushinteger(L, character.MaxHp);
            Melua.lua_settable(L, -3);

            Melua.lua_pushstring(L, "sp");
            Melua.lua_pushinteger(L, character.Sp);
            Melua.lua_settable(L, -3);

            Melua.lua_pushstring(L, "maxSp");
            Melua.lua_pushinteger(L, character.MaxSp);
            Melua.lua_settable(L, -3);

            Melua.lua_pushstring(L, "stamina");
            Melua.lua_pushinteger(L, character.Stamina);
            Melua.lua_settable(L, -3);

            Melua.lua_pushstring(L, "hair");
            Melua.lua_pushinteger(L, character.Hair);
            Melua.lua_settable(L, -3);

            return(1);
        }
コード例 #5
0
ファイル: Melua.cs プロジェクト: xyfc/Melua
        public void tostring()
        {
            var L = Melua.luaL_newstate();

            Melua.lua_pushinteger(L, 123);
            var str = Melua.lua_tostring(L, -1);

            Assert.Equal("123", str);

            Melua.lua_newtable(L);
            Assert.Equal(null, Melua.lua_tostring(L, -1));

            Melua.lua_pushstring(L, "foobar");
            Assert.Equal("foobar", Melua.lua_tostring(L, -1));
        }
コード例 #6
0
        /// <summary>
        /// Returns a table with information about the NPC.
        /// </summary>
        /// <remarks>
        /// Result:
        /// {
        ///		string name,        -- NPCs name
        ///		string dialogName,  -- Name of NPCs main dialog function
        /// }
        /// </remarks>
        /// <param name="L"></param>
        /// <returns></returns>
        private int getnpc(IntPtr L)
        {
            var conn      = this.GetConnectionFromState(L);
            var character = conn.ScriptState.CurrentNpc;

            Melua.lua_newtable(L);

            Melua.lua_pushstring(L, "name");
            Melua.lua_pushstring(L, character.Name);
            Melua.lua_settable(L, -3);

            Melua.lua_pushstring(L, "dialogName");
            Melua.lua_pushstring(L, character.DialogName);
            Melua.lua_settable(L, -3);

            return(1);
        }