PKG_NAME:=lua
PKG_VERSION:=5.1.4
PKG_NAME:=lua
PKG_VERSION:=5.1.4
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://www.lua.org/ftp/ \
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://www.lua.org/ftp/ \
last -= n-1;
--- a/src/lua.c
+++ b/src/lua.c
last -= n-1;
--- a/src/lua.c
+++ b/src/lua.c
+ lua_State *L;
+ size_t memused;
+ size_t peak_memused;
+ lua_State *L;
+ size_t memused;
+ size_t peak_memused;
+ size_t max_memused;
+ int collecting;
+} script_info_t;
+ size_t max_memused;
+ int collecting;
+} script_info_t;
+ return NULL;
+ }
+ info->memused += nsize;
+ return NULL;
+ }
+ info->memused += nsize;
-+ if(info->max_memused > 0 && nsize > osize && info->memused >= info->max_memused) {
++ if(info->max_memused > 0 && nsize > osize &&
++ (info->memused >= info->max_memused || info->memused >= info->gc_memused)) {
+#ifdef LOW_MEM_DEBUG
+ printf("LOW MEM: 1 osize=%zd, nsize=%zd, used=%zu, peak=%zu, need=%zd\n", osize, nsize,
+ info->memused, info->peak_memused, (info->memused - info->max_memused));
+#ifdef LOW_MEM_DEBUG
+ printf("LOW MEM: 1 osize=%zd, nsize=%zd, used=%zu, peak=%zu, need=%zd\n", osize, nsize,
+ info->memused, info->peak_memused, (info->memused - info->max_memused));
+
+static int set_memory_limit(lua_State *L)
+{
+
+static int set_memory_limit(lua_State *L)
+{
-+ int limit = luaL_checknumber(L, 1);
++ int hardlimit = luaL_checknumber(L, 1);
++ int softlimit = luaL_optnumber(L, 2, 0);
++
+ script_info_t *info;
+ lua_getallocf(L, (void *)(&info));
+
+ script_info_t *info;
+ lua_getallocf(L, (void *)(&info));
+
-+ if( limit >= 0 )
-+ info->max_memused = limit;
++ if( hardlimit >= 0 )
++ {
++ if( softlimit <= 0 )
++ softlimit = (int)((float)hardlimit * 0.75);
++
++ info->max_memused = hardlimit;
++ info->gc_memused = softlimit;
++ }
-+ lua_pushnumber(L, limit);
-+ return 1;
++ lua_pushnumber(L, hardlimit);
++ lua_pushnumber(L, softlimit);
++ return 2;
+}
+
+static int get_memory_limit(lua_State *L)
+}
+
+static int get_memory_limit(lua_State *L)
+ script_info_t *info;
+ lua_getallocf(L, (void *)(&info));
+ lua_pushnumber(L, info->max_memused);
+ script_info_t *info;
+ lua_getallocf(L, (void *)(&info));
+ lua_pushnumber(L, info->max_memused);
++ lua_pushnumber(L, info->gc_memused);
++ return 2;
+}
+
+
static lua_State *globalL = NULL;
static const char *progname = LUA_PROGNAME;
+}
+
+
static lua_State *globalL = NULL;
static const char *progname = LUA_PROGNAME;
int main (int argc, char **argv) {
int status;
struct Smain s;
int main (int argc, char **argv) {
int status;
struct Smain s;
/* Checking 'sizeof(lua_Integer)' cannot be made in preprocessor on all compilers.
*/
#ifdef LNUM_INT16
/* Checking 'sizeof(lua_Integer)' cannot be made in preprocessor on all compilers.
*/
#ifdef LNUM_INT16
status = lua_cpcall(L, &pmain, &s);
report(L, status);
lua_close(L);
status = lua_cpcall(L, &pmain, &s);
report(L, status);
lua_close(L);