Reputation: 310
I want to pass an c array to the running lua script. The c array is uin32_t with 16Bit values. So high and low word with 1024 uint32_t values. So 2048 16 bit values.
When I hit the 512 uint32_t value the lua code throws an LUA_ERRMEM error cause there is no more free memory. This is absolutely possible, as my application runs on a STM32F2XX µC.
I do call lua_checkstack every iteration with 20 extra stack slots to allocate. So in theory the stack should always be big enough. But not, if it can't realloc more memory.
So my idea was, that I place it in the external memory, but I don't know how. I already have a working linker section for the external PSRAM but I can't just do attribute ((section (".psram"))) somewhere, right?
So do I need to write my own lua_newstate function? Or is there another way to place the lua stack somewhere I want it?
Upvotes: 0
Views: 164
Reputation: 121
Lua stack is just one of lua objects. Memory for every object allocated dynamically by allocator. Usualy Lua uses functions realloc
and free
, look source code here
You can write your own allocator, you can change behavior of realloc
and free
to use PSRAM. How to do this - another interesting question.
P.S. Explore Lua source code: it not so big and it informative.
Upvotes: 1