Pls replace thisif (ret != 0 && ptr == MEMERRMSG) ret = LUA_ERRMEM;Withif (ret != 0 && strcmp(ptr, MEMERRMSG) == 0) ret = LUA_ERRMEM;