-->
Page 2 of 3

Re: Relationship between heap and flash

PostPosted: Wed Jan 14, 2015 8:09 am
by Hans174
Is there way with lua to do something similar and reduce the demand on the heap?


Yes, there is.

The nodeMCU version of LUA based on eLUA and eLUA programs can be stored in the FLASH area of a controller.

This should increase the heap.

Re: Relationship between heap and flash

PostPosted: Thu Jan 15, 2015 9:03 am
by Hoksmur
One more way. It isn't fast, but works not bad.
And here the same colored.

Code: Select all-- small 'chunk' interpreter. Usage:
-- intr=loadfile("interpret.lua")
-- test: print( intr("test.lua", [startstring, endstring[, subchunk's params] ] ) )

-- function(fn, stidx, eidx, ...)
local fn, stidx, eidx,i
fn,stidx,eidx = ...
i=0
--for i,j in pairs(arg1) do print("P:",i,j) end
local rez="";local buf="";succ=true
local cidx=1;local cond=true
if not stidx then stidx=1 end
file.open(fn)
repeat
 i=i+1
 tmr.wdclr()
  buf=file.readline() tmr.wdclr()
  if buf and cidx>=stidx then
    if not succ then
     rez=rez..buf
   else
     rez=buf
   end
   succ, rx=pcall( loadstring(rez), select(4,...) )
 print("read str:",i)
  end
  cidx=cidx+1
  if eidx then cond=(cidx<=eidx) else cond=true end
until not( buf and cond)
file.close()
return rx

Re: Relationship between heap and flash

PostPosted: Fri Jan 16, 2015 10:00 pm
by GeoNomad
picstart wrote: Is there way with lua to do something similar and reduce the demand on the heap?


To maintain heap, I have been coding functions as files and using dofile() to run them. The heap remains unchanged as long as only local variables are used and functions (if used at all) are deleted when no longer necessary.

This undoubtedly is slower, but most of the time, it is not important.

Re: Relationship between heap and flash

PostPosted: Sat Jan 17, 2015 12:26 pm
by raz123
Hoksmur wrote:One more way. It isn't fast, but works not bad.
And here the same colored.

Code: Select all-- small 'chunk' interpreter. Usage:
-- intr=loadfile("interpret.lua")
-- test: print( intr("test.lua", [startstring, endstring[, subchunk's params] ] ) )

-- function(fn, stidx, eidx, ...)
local fn, stidx, eidx,i
fn,stidx,eidx = ...
i=0
--for i,j in pairs(arg1) do print("P:",i,j) end
local rez="";local buf="";succ=true
local cidx=1;local cond=true
if not stidx then stidx=1 end
file.open(fn)
repeat
 i=i+1
 tmr.wdclr()
  buf=file.readline() tmr.wdclr()
  if buf and cidx>=stidx then
    if not succ then
     rez=rez..buf
   else
     rez=buf
   end
   succ, rx=pcall( loadstring(rez), select(4,...) )
 print("read str:",i)
  end
  cidx=cidx+1
  if eidx then cond=(cidx<=eidx) else cond=true end
until not( buf and cond)
file.close()
return rx


Pardon my ignorance; could you describe what this function accomplishes, in simple English?