Announcement

Collapse
No announcement yet.

Bug: Application.Sleep accepts any valid lua type as the passed argument

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bug: Application.Sleep accepts any valid lua type as the passed argument

    try this silly bit of code:

    Code:
    --Application.Sleep accepts any valid lua [type], should only accept lua type [number] or fwiw: default to 0 [number]
    local fn=Dialog.Message("Sleep","i should not be called");
    Application.Sleep(fn); --calls the function ?
    Application.Sleep(Dialog.Message("Sleep","i should not be called"));
    Application.Sleep("0");
    Application.Sleep({});
    Tested on AMS 8x and on SUF 9x (probably in all IR Apps ...)

    Suggestion: Application.Sleep should be "dummy proofed" or default to 0 [number] on any bad argument or type passed to it

  • #2
    I'll go through your examples:
    First one
    Code:
    local fn=Dialog.Message("Sleep","i should not be called");
    Application.Sleep(fn); --calls the function ?
    It calls the function, because you call it on the line `local fn=.....()'. The Application.Sleep call isn't calling it. You're calling Dialog.Message and putting the result in fn. The result of Dialog.Message is numeric, so you're providing Application.Sleep with a number. Done.

    Second one
    Code:
    Application.Sleep(Dialog.Message("Sleep","i should not be called"));
    This one is identical to the first one, you call the function yourself (hence the parenthesis after Dialog.Message with the two arguments). Application.Sleep is getting the result of the Dialog.Message call, which is numeric. Still precisely what it's supposed to do.

    Third one
    Code:
    Application.Sleep("0");
    Even though you're not providing a number, you're providing a numeric value. Application.Sleep appears to be converting numeric string values back to integers and it's considered a valid delay in that case. If you change "0" to "1000" you'll notice it'll wait for a second. Change it to "abcd" and it'll wait 0 milliseconds. I agree that this can be confusing, because there is no consistency. It shouldn't support a string all together.

    Fourth one
    Code:
    Application.Sleep({});
    Ditto, it shouldn't support strings, but obviously it shouldn't allow tables either. It should luaL_checkint the argument and only allow number values.

    So you're right about the second two and the fact that it accepts any type of argument. It'll check if a lua_tonumber works on the value (which it does on numeric strings) and uses that value, it doesn't throw an error if this isn't possible.
    Bas Groothedde
    Imagine Programming :: Blog

    AMS8 Plugins
    IMXLH Compiler

    Comment


    • #3
      haha Bas, realized the method in my own madness for the first two...
      (did'nt bother checking the action xml either to see if any constraints)

      but yo, some concistancy would be good and inline with the related Help info [number]

      Application.Sleep(happynewyear!)

      Comment


      • #4
        Originally posted by Eagle View Post
        haha Bas, realized the method in my own madness for the first two...
        (did'nt bother checking the action xml either to see if any constraints)

        but yo, some concistancy would be good and inline with the related Help info [number]

        Application.Sleep(happynewyear!)
        I agree, it should accept only numbers and let you know if something's wrong. Happy New Year!
        Bas Groothedde
        Imagine Programming :: Blog

        AMS8 Plugins
        IMXLH Compiler

        Comment

        Working...
        X