unknown lua bug

Case number:699969-989845
Topic:General
Opened by:Seagat2011
Status:Closed
Type:Bug
Opened on:Tuesday, June 14, 2011 - 03:03
Last modified:Monday, September 12, 2011 - 06:17

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

(Tue, 06/14/2011 - 03:03  |  8 comments)


Joined: 08/24/2010

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.

Joined: 08/24/2010
Status: Open » Open

k

Joined: 06/17/2010

Some code to test it?

Joined: 08/24/2010

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

Joined: 06/17/2010

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.

Joined: 08/24/2010

ah, in that example, null s/b nil.

Joined: 08/24/2010

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.

Tlaloc's picture
User offline. Last seen 14 weeks 2 days ago. Offline
Joined: 08/04/2008
Groups: Mojo Risin'
Status: Open » Closed

The spec for Lua says: 2.5.3 ... Both and and or use short-cut evaluation; that is, the second operand is evaluated only if necessary ... http://www.lua.org/manual/5.1/manual.html#2.5.3

Sitemap

Developed by: UW Center for Game Science, UW Institute for Protein Design, Northeastern University, Vanderbilt University Meiler Lab, UC Davis
Supported by: DARPA, NSF, NIH, HHMI, Amazon, Microsoft, Adobe, RosettaCommons