unknown lua bug

Started by Seagat2011

Seagat2011 Lv 1

There's a strange lua bug in the recipe editor. I don't know what it is because it seems to be evolving.

Seagat2011 Lv 1

I think it's the Logical operators: (AND,OR) they seem to be using a short-cut evaluation.(i.e. the conjunction-AND or disjunction-OR only evaluates the second argument if the first argument is found to be False) (foldit) Lua has never done this before.

Seagat2011 Lv 1

Hi, rav, thanks for your help.

The code I was testing is here[2]:

The code calls a clear_all_bits method that was built into the lua scripting library[1]:

function bit.clear_all_bits ()
  local j
  local k
  local m
  j = #_n
  k = #_token
  if ((j >= k) and (#_n ~= null)) then
    m = j
  elseif ((k > j) and (#_token ~= null)) then
    m = k
  end
  for idx = 1,m do
    if (idx <= j) then
      _n [idx] = 0
    end
    if (idx <= k) then
      _n [_token[idx]] = 0
    end
  end
end

..I couldn't get the code to reliably return a sizeof(_n) value so I abandoned it and shared this less robust alternative to foldit wiki library

function bit.clear_all_bits ()
  local j
  local k
  local m
  j = #_n
  k = #_token
  m = j
  if (k > j) then
    m = k
  end
  for idx = 1,m do
    if (idx <= j) then
      _n [idx] = 0
    end
    if (idx <= k) then
      _n [_token[idx]] = 0
    end
  end
end

REFERENCES

  1. http://foldit.wikia.com/wiki/Lua_Script_Library#bit.clear_all_bits_–_Clear_bit-field
  2. "Lua Script Library - FoldIt Wiki - a Wikia Gaming wiki" - http://foldit.wikia.com/wiki/Lua_Script_Library#Bit_-_A_fold.it.21_version_of_bit_manipulation_for_the_standard_library

Rav3n_pl Lv 1

Wow, do we really need use bits for configuration?
More readable is something like:

config.useHelices=true
config.useSheets=true
config.useLoops=true

then just check in code for true/false… IMHO.

Or you found some better use for it than it is shown in wiki? I`m not sure we can gain any speed/memory using so much nested functions for set/read simple logical information.

Also afik all languages are using "shortcuts" for logical functions, thats why (when needed calculation) I evaluate values b4 I check results of comparison.

Seagat2011 Lv 1

A config object is nice because it does makes the code scalable, but that provided example assumes a correct return type of boolean; for fail-proof code, there should be some form of exception handling.