Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Sat Dec 05, 2009 1:07 am   

[3.12] Lua commands affecting child windows
 
Unless I'm doing something completely wrong here, I don't think child windows should be affected by lua commands via the following code:

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <alias name="showcal" language="Lua" copy="yes">
    <value><![CDATA[do
local days_in_month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }

  local function is_leap_year(year)
    return year % 4 == 0 and (year % 100 ~= 0 or year % 400 == 0)
  end

  function get_days_in_month(month, year)
    if month == 2 and is_leap_year(year) then
      return 29
    else
      return days_in_month[month]
    end
  end
end

function get_day_of_week(dd, mm, yy)
  dw=os.date('*t',os.time{year=yy,month=mm,day=dd})['wday']
  return dw,({"Sun","Mon","Tue","Wed","Thu","Fri","Sat" })[dw]
end

function get_date_parts(date_str)
  _,_,y,m,d=string.find(date_str, "(%d+)-(%d+)-(%d+)")
  return tonumber(y),tonumber(m),tonumber(d)
end

-- based on original code from sam_lie
function show_calendar(cdate)
  local yy, mm, dd = get_date_parts(cdate)
  local month_days = get_days_in_month(mm, yy)
  local day_week = get_day_of_week(1, mm, yy)

        --- day in which the calendar day start.. 1=Sunday, 2="Monday"
  local day_start = 1

  local days_of_week = {{ "Sun", 1 }, { "Mon", 2 } , { "Tue", 3 }, { "Wed", 4 }, { "Thu", 5 }, { "Fri", 6 }, { "Sat", 7 }}
  local days_of_week_ordered = {}
 
  for k=1, 7 do
    p = k+day_start-1
    if (p>7) then
      p=p-7
    end
    v = {}
    v.dayname = days_of_week[p][1]
    v.daynum = days_of_week[p][2]
    table.insert(days_of_week_ordered, v)
  end

  local out = "<h3>" .. cdate .. "</h3>"
  out = out .. "<tr>"
  for i,v in ipairs(days_of_week_ordered) do
    out = out .. v.dayname .. "  "

    if (day_week == v.daynum) then
      d = - i + 2
    end
  end
  out = out .. "<p>"

  while (d < month_days) do
    out = out .. "<p>"
    for i,v in ipairs(days_of_week) do
      if (d>=1 and d <=month_days) then
        if (d<10) then
          if (d==dd) then
          out = out .. "<font color='red'> 0" .. d .. "</font>  "
          else
          out = out .. " 0" .. d .. "  "
          end
        else
        if (d==dd) then
          out = out .. "<font color='red'> " .. d .. "</font>  "
        else
        out = out .. " " .. d .. "  "
        end
      end
      else
        out = out .. "     "
      end

      d = d + 1
    end
    out = out .. "<p>"
  end

  out = out .. "<p></tr>"
 
  return out
end

zs.cmd.mxp(show_calendar(zs.param(1) .. '-' .. zs.param(2) .. '-' .. zs.param(3)))
]]></value>
  </alias>
</cmud>


The way it works is you do 'showcal 2009 12 04' and it'll show a calendar of December, 2009, with the date 04 highlighted in red. Works perfectly on the main window. However, on my child window, which I use to capture chats from Aardwolf, things are broken up.

Instead of:

Code:
(Group) You sigh.


I see:

Code:
(
Group
)
You sigh.


And I, for the life of me, cannot figure it out. So, I'm assuming it's a bug, to say the least, unless I truly am missing something. Thanks!

Charneus
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Sat Dec 05, 2009 4:10 am   
 
So, I figured out what the problem is... had to get rid of the <tr></tr> bit because it wasn't needed. (Honestly, can't remember why those were in there...).

However, I still think it's a bug that it was affecting the child window, and it may have something to do with the MXP instead...

Charneus

Edit: I take that back. My alias 'showdate' worked well (it uses: showcal %time(yyyy) %time(mm) %time(dd)), but when I did showcal 2000 3 12, it messed up the child window again.
Reply with quote
wrym
Magician


Joined: 06 Jul 2007
Posts: 349
Location: The big palace, My own lil world

PostPosted: Sun Dec 06, 2009 1:14 am   
 
Not sure i see what "(Group) you sigh." has to do with this alias, but your tags don't look balanced. i don't see enough <tr> or </p>, but don't think you want to use <p> <br> should do it for you.

Furthermore... i actually don't see <tr></tr> in the mxp spec http://www.zuggsoft.com/zmud/mxp.htm
_________________
"To the engineer, all matter in the universe can be placed into one of two categories: (1) things that need to be fixed, and (2) things that will need to be fixed after you've had a few minutes to play with them" - Scott Adams, The Dilbert Principle
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Sun Dec 06, 2009 2:31 am   
 
wrym wrote:
Not sure i see what "(Group) you sigh." has to do with this alias, but your tags don't look balanced. i don't see enough <tr> or </p>, but don't think you want to use <p> <br> should do it for you.

Furthermore... i actually don't see <tr></tr> in the mxp spec http://www.zuggsoft.com/zmud/mxp.htm


The "(Group) You sigh." bit is what is being sent to my child windows via captures. On the main window, it shows up just fine (i.e., (Group) You sigh.), but after running the showcal, in my CHILD window, it shows up broken.

However, I think you're correct about the closing bit. I had already taken out the <tr> bit, considering I didn't need it, and changed all the <p> to <p></p>, and it seems to work right now. Thanks for that suggestion. ;)

Either way, I don't think it should be affecting the child window at all, though I'm not sure if it's the mxp itself, or the lua code.

Charneus
Reply with quote
wrym
Magician


Joined: 06 Jul 2007
Posts: 349
Location: The big palace, My own lil world

PostPosted: Sun Dec 06, 2009 3:17 am   
 
If anything i'ld say that the unclosed tags was causing some interference somehow, some commands are auto closed at end of line but not all, can't remember which. are the parenths and group portion colored differently?

but still not sure why your saying this code is causing the child window to act wierd.
_________________
"To the engineer, all matter in the universe can be placed into one of two categories: (1) things that need to be fixed, and (2) things that will need to be fixed after you've had a few minutes to play with them" - Scott Adams, The Dilbert Principle
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Sun Dec 06, 2009 5:15 am   
 
wrym wrote:
If anything i'ld say that the unclosed tags was causing some interference somehow, some commands are auto closed at end of line but not all, can't remember which. are the parenths and group portion colored differently?

but still not sure why your saying this code is causing the child window to act wierd.


Did you read what I was saying? I don't know why the code is making the child window act weird, either, but it is.

Let me break it down for you.

1. I have triggers that capture chats into its own window, Chat. I gag them from the main window, as well.
2. Using the above code, I type 'showcal 2009 12 05' on the command line. The calendar shows up naturally, in my main window.
3. Any chat that comes across my screen still gets captured to the Chat window. However, it's now broken up (case in point, the broken 'sigh' bit in the first post.)
4. If I ungag the chat from the main window (toggle command I use), then the line shows up fine. Nothing broken about it.

Therefore, everything in the main window is fine, but running the showcal alias using the code above causes the capturing to screw up or something, and I don't know why. Closed tags or not, it doesn't make sense for it to affect the child window.

Charneus
Reply with quote
wrym
Magician


Joined: 06 Jul 2007
Posts: 349
Location: The big palace, My own lil world

PostPosted: Sun Dec 06, 2009 6:30 pm   
 
I didn't catch that your captures were fine before running the alias but not afterwards. Have you run this in a blank session, I was unable to reproduce your problem.
_________________
"To the engineer, all matter in the universe can be placed into one of two categories: (1) things that need to be fixed, and (2) things that will need to be fixed after you've had a few minutes to play with them" - Scott Adams, The Dilbert Principle
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Dec 07, 2009 9:30 pm   
 
Keep in mind that there is only a single global Lua "namespace" in CMUD. In other words, if you define a Lua function within some alias (using the Lua "function" command), that function gets added to the global Lua namespace and becomes available to any other Lua script in any window, including child windows. Lua doesn't have any knowledge of CMUD windows or classes or scoping rules.
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Tue Dec 08, 2009 1:54 am   
 
Weird, because I have absolutely no lua scripts other than what's in my main window. There isn't anything attacked to the child window at all. It just serves as a catchall for chats.

I'm wondering (and I should have checked this myself) if it's possible the MUD is sending something that is causing it to break up. Only thing is, it should happen in the main window, too, and not just the child window... In any case, I can't even reproduce it in an untitled session, even copying the same script over.

Charneus
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net