As the title says... Chat on...

User avatar
By cal
#18691
cwilt wrote:
cal wrote:Moin,

IMHO lua is mostly a glue or prototype language.
If you identify proper functions that need speed, encode them in c and call them from lua.

My € 0,02 cents,
Cal


Don't want to hijack but can you point me to an example call to C routine?


All lua modules can be taken as an example. "app/modules". Nearly all of luas functionality is written in c.
If you want to get started understanding the interface the following may help.

viewtopic.php?f=24&t=2526
I had fun writing that.
Leave a note if you found it useful.

Cal
User avatar
By LeprA
#20304 I haven't found the time for more investigation until now but i have found a solution:

Original code from the first post)
Code: Select allfunction forwardandrewind()
      if(forward == 1) then
         forward = 0
         gpio.write(3,gpio.HIGH)
      else
         forward = 1
         gpio.write(3,gpio.LOW)
      end
         
      for x=1,16000 do
         gpio.write(4,gpio.HIGH)
         tmr.delay(1)
         gpio.write(4,gpio.LOW)
         tmr.delay(1)
         tmr.wdclr()
      end
      tmr = nil

      print(node.heap())
   end


I found the problem with this code its the tmr.wdclr() when called to often it leaks hell of memory instead it should only be called when needed.

example)
Code: Select allfunction forwardandrewind()
      if(forward == 1) then
         forward = 0
         gpio.write(3,gpio.HIGH)
      else
         forward = 1
         gpio.write(3,gpio.LOW)
      end
         
      for x=1,16000 do
         gpio.write(4,gpio.HIGH)
         tmr.delay(1)
         gpio.write(4,gpio.LOW)
         tmr.delay(1)
         if(x%1000) then
              tmr.wdclr()
         end
      end
      tmr = nil

      print(node.heap())
   end


Here i substitute the
tmr.wdclr()
with
if(x%1000) then
tmr.wdclr()
end


and now it do not leak memory anymore....

So if someone else doing this foolish mistake then you got the solution for it :D