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

User avatar
By Hans174
#7276
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.
User avatar
By Hoksmur
#7365 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
User avatar
By GeoNomad
#7482
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.
User avatar
By raz123
#7519
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?