lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi there,

i have the following a little complicated looking code. It's not very useful, it was just a test of how something could be done. But i think i discovered a bug in lua4.1w4, because if you replace the multiple assingnment with two straight assings (what you definatley would do in this code anyway, because there's no need for the multiple one) then it works fine. if you keep the multiple assignment in the middle the assignment assings the return of strsub to "Return" AND "self.Pos" wich is quite strange.

-- snip --

do
   local myfunc=function(self)
      local Return

      print(self.Pos, type(self.Pos), self.Step, type(self.Step))

      if self.Pos<=strlen(self.String) then

         self.Pos,           Return =
self.Pos+self.Step, strsub(self.String,self.Pos,self.Pos+self.Step-1)

--  Uncomment this and comment the above and everything works fine!
--         Return=strsub(self.String,self.Pos,self.Pos+self.Step-1)
--         self.Pos=self.Pos+self.Step

         return Return

      else
         return false
      end

   end

   local MetaTable={call=myfunc}

   function strstep(String,Step)
      local Return
      if Step==nil then Step=1 end

      Return={String=String,Pos=1,Step=Step}
      metatable(Return,MetaTable)

      return Return,Return()
   end

end


local Function

Function,String=strstep('1234567890',3)
while String~=false do
   print(String)
   String=Function()
end

-- snip --

Or do i have a strange typo in there?


-- http://www.DasGenie.com/ --
AIM: DasGenieDotCom - ICQ: 22369156

"Glück ist eine Verpflichtung. Wir sollten uns für das Glück entscheiden.
Wir sollten daran arbeiten. Und dabei sollten wir denen, die uns am
nächsten stehen, und auch jenen, die nur zufällig unseren Pfad kreuzen,
eine Hilfe sein, damit auch sie ihr Glück finden." - Richard Koch