mirror of
https://github.com/opentx/opentx.git
synced 2025-07-19 06:15:10 +03:00
Projectkk2glider/lua bitmap free (#4075)
* Better memory stats (CLI) * Bitmap buffer overflow check added * Lua bitmap improvements * Proper handling of symbolic links in simulator * S6R Lua script fixes: * added progress screen while loading bitmaps * memory for bitmaps is now freed when leaving the script * S6R Lua script: improved bitmap loading * * Lua Themes and Widgets moved to separate file and separate Lua state * Stand-alone, mixer and function scripts now behave the same as on Taranis (restarted after the stand-alone script was run) * both Lua states are independent: Themes and Widgets is initialized only at the start, the other one is initialized before and after the stand-alone script is run * Better leak test and report in BitmapBuffer * Re #3318: Lua compiler enabled in simu and Companion simulator. Usage: * any time <xxx>.lua file is about to be loaded and if file <xxx>.lua.src exists: * load contents of <xxx>.lua.src * compile Lua code * save compiled code into <xxx>.lua (effectively overwrites existing file) * immediately following the compilation the real file loading is done from <xxx>.lua (which by now contains compiled Lua bytecode)
This commit is contained in:
parent
ae383cd6a4
commit
92553b6589
18 changed files with 745 additions and 554 deletions
|
@ -317,6 +317,9 @@ static int luaLcdDrawSource(lua_State *L)
|
|||
}
|
||||
|
||||
#if defined(COLORLCD)
|
||||
|
||||
#define LUA_BITMAPHANDLE "BITMAP*"
|
||||
|
||||
/*luadoc
|
||||
@function Bitmap.open(name)
|
||||
|
||||
|
@ -334,8 +337,15 @@ static int luaOpenBitmap(lua_State * L)
|
|||
|
||||
BitmapBuffer ** ptr = (BitmapBuffer **)lua_newuserdata(L, sizeof(BitmapBuffer *));
|
||||
*ptr = BitmapBuffer::load(filename);
|
||||
TRACE("luaOpenBitmap: %p", *ptr);
|
||||
|
||||
luaL_getmetatable(L, "luaL_Bitmap");
|
||||
if (*ptr == NULL && G(L)->gcrunning) {
|
||||
luaC_fullgc(L, 1); /* try to free some memory... */
|
||||
*ptr = BitmapBuffer::load(filename); /* try again */
|
||||
TRACE("luaOpenBitmap: %p (second try)", *ptr);
|
||||
}
|
||||
|
||||
luaL_getmetatable(L, LUA_BITMAPHANDLE);
|
||||
lua_setmetatable(L, -2);
|
||||
|
||||
return 1;
|
||||
|
@ -343,7 +353,9 @@ static int luaOpenBitmap(lua_State * L)
|
|||
|
||||
static BitmapBuffer * checkBitmap(lua_State * L, int index)
|
||||
{
|
||||
return *(BitmapBuffer **)luaL_checkudata(L, index, "luaL_Bitmap");
|
||||
BitmapBuffer ** b = (BitmapBuffer **)luaL_checkudata(L, index, LUA_BITMAPHANDLE);
|
||||
if (!*b) luaL_error(L, "null Image");
|
||||
return *b;
|
||||
}
|
||||
|
||||
|
||||
|
@ -374,7 +386,9 @@ static int luaGetBitmapSize(lua_State * L)
|
|||
|
||||
static int luaDestroyBitmap(lua_State * L)
|
||||
{
|
||||
delete checkBitmap(L, 1);
|
||||
BitmapBuffer * ptr = checkBitmap(L, 1);
|
||||
TRACE("luaDestroyBitmap: %p", ptr);
|
||||
delete ptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -387,7 +401,7 @@ const luaL_Reg bitmapFuncs[] = {
|
|||
|
||||
void registerBitmapClass(lua_State * L)
|
||||
{
|
||||
luaL_newmetatable(L, "luaL_Bitmap");
|
||||
luaL_newmetatable(L, LUA_BITMAPHANDLE);
|
||||
luaL_setfuncs(L, bitmapFuncs, 0);
|
||||
lua_pushvalue(L, -1);
|
||||
lua_setfield(L, -2, "__index");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue