Skip to content

Commit e71b699

Browse files
at
1 parent 908cbd1 commit e71b699

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,46 @@ error: timeout error
424424
425425
~~~
426426

427+
### Memory usage
428+
by using the method **set_memory_limit** you can control the max ram usage of lua, the default its 100mb
429+
<h5 style="color:red;">NOTE THAT EXTRA MEMORY ALOCATED OUTSIDE CALLBACKS OR EVALUATIONS ARE CONSIDER UNPROTECTED GEHAVIOR
430+
AND IT WILL KILL THE APPLICATION
431+
432+
</h5>
433+
<!--codeof:exemples/evaluation/memory_usage.c-->
434+
~~~c
435+
#include "LuaCEmbed.h"
436+
LuaCEmbedNamespace lua_n;
437+
438+
439+
440+
int main(int argc, char *argv[]){
441+
442+
lua_n = newLuaCEmbedNamespace();
443+
LuaCEmbed * l = lua_n.newLuaEvaluation();
444+
int one_mega = 1;
445+
lua_n.set_memory_limit(l,one_mega);
446+
lua_n.evaluate(l,"t = 'a';while true do t = t .. t end");
447+
448+
if(lua_n.has_errors(l)){
449+
printf("error: %s\n",lua_n.get_error_message(l));
450+
}
451+
452+
lua_n.free(l);
453+
454+
return 0;
455+
}
456+
~~~
457+
458+
It will produce:
459+
460+
<!--codeof:tests/main_test/evaluation/T_memory_usage/expected.txt-->
461+
~~~txt
462+
463+
error: not enough memory
464+
465+
~~~
466+
427467
### Callbacks
428468
Callbacks i'ts a way to make c functions assesible in lua code, this it's the most basic callback:
429469

0 commit comments

Comments
 (0)