Метатабличный / Говнокод #25346 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
do debug.getinfo(1).func() end --рекурсия
do debug.getinfo(2).func() end --вылет нахуй интерпретатора 5.3 версии без ошибки.
do debug.getinfo(3).func() end --не существует с таким индексом. Ошибка.

Запостил: 3oJIoTou_xyu 3oJIoTou_xyu, (Updated )

Комментарии (30) RSS

  • When you call debug.getinfo(n) for some number n, you get data about the function active at that stack level. For instance, if n is 1, you get data about the function doing the call. (When n is 0, you get data about getinfo itself, a C function.) If n is larger than the number of active functions in the stack, debug.getinfo returns nil. When you query an active function, calling debug.getinfo with a number, the result table has an extra field, currentline, with the line where the function is at that moment. Moreover, func has the function that is active at that level.
    https://www.lua.org/pil/23.1.html

    Похоже lua сгнил
    Ответить
    • Я понимаю 1 случай и 3 случай, 3 случай как в документации. И 1 тоже, я ведь получаю 1 уровень блока и вызываю его же из себя по этому рекурсия. А 2 чо за хуйня
      Ответить
      • Выведи debug.getinfo(2), может быть понятнее станет что там.
        Ответить
        • в репле:

          > do print(debug.getinfo(2)) end
          table: 0000000000d69f00

          но:

          > do local x = {}; print(x) x() end
          table: 0000000000d6a400
          stdin:1: attempt to call a table value (local 'x')
          stack traceback:
          stdin:1: in main chunk
          [C]: in ?
          Ответить
            • > do for k,v in pairs(debug.getinfo(2)) do print(k, v) end end
              currentline -1
              namewhat
              linedefined -1
              isvararg true
              lastlinedefined -1
              source =[C]
              nups 0
              func function: 0000000000401dc0
              istailcall false
              short_src [C]
              nparams 0
              what C
              Ответить
              • Нихуя не понятно.
                с do for k,v in pairs(debug.getinfo(0)) do print(k, v) end end выводит фактически аналогичные параметры.
                Только отличает ее функция и параметр namewhat (там вроде фиелд написано). Притом что если я вызову func вызовется debug.getinfo.
                Значит неожиданно стек вызовов в lua индексируется с 0! И 0 и последние вызовы вызываются из С, так как currentline -1 говорит нам о том что это вызвалось вне луа. Значит если в даном случае вызвать debug.getinfo(1).func() то debug.getinfo вызовет само из себя. следовательно рекурсия.
                Тогда что лежит во 2 блоке?
                Ответить
  • Исходный код главной страницы официального сайта UMI.CMS радует нас такой вот версткой:
    <h2 class="h2_style_main_page" style="margin-bottom: 0; display: inline-block; *width: 281px; margin-left: -21px; float: left;">Отзывы от владельцев сайтов</h2>
    <a style="margin-bottom: 0; position: relative; bottom: 0; text-decoration: none; display: inline-block; float: right; right: 64px; top: 3px; font-weight: bold;" href="/product/reviews/">Все</a>
    <h2 class="h2_style_main_page" style="margin-bottom: 0; display: inline-block; float: right; margin-right: 162px;">Отзывы от разработчиков сайтов</h2>
    <div class="clear" style="height: 1px; margin: 0; padding: 0;"> </div>
    </div>
    <div class="clear" style="height: 1px; margin: 0; padding: 0;"> </div>
    <div id="respones" class="respones" style="width: 920px !important; *height: 420px !important;">
    <div id="responesContainer" style="width: 920px !important;">
    Ответить

Добавить комментарий

Переведи на "PHP", guest!

    А не использовать ли нам bbcode?


    8