1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-10-10 00:11:29 +00:00

Add special memory allocator for Lua that should take some memory stress away from heavy scripting.

This commit is contained in:
fgenesis 2013-08-26 21:02:46 +02:00
commit 69890093bd
5 changed files with 479 additions and 2 deletions

View file

@ -9952,7 +9952,7 @@ static const struct {
//============================================================================================
ScriptInterface::ScriptInterface()
: baseState(NULL)
: baseState(NULL), _sballoc(8, 128)
{
}
@ -9975,9 +9975,15 @@ void ScriptInterface::reset()
init();
}
void *ScriptInterface::the_alloc(void *ud, void *ptr, size_t osize, size_t nsize)
{
ScriptInterface *this_ = (ScriptInterface*)ud;
return this_->_sballoc.Alloc(ptr, nsize, osize);
}
lua_State *ScriptInterface::createLuaVM()
{
lua_State *state = lua_open(); /* opens Lua */
lua_State *state = lua_newstate(the_alloc, this); /* opens Lua */
luaopen_base(state); /* opens the basic library */
luaopen_table(state); /* opens the table library */
luaopen_string(state); /* opens the string lib. */

View file

@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define SCRIPTINTERFACE_H
#include "../BBGE/Base.h"
#include "../BBGE/MemoryAllocatorSmallBlock.h"
struct lua_State;
@ -105,8 +106,10 @@ protected:
void destroyLuaVM(lua_State *state);
lua_State *createLuaThread(const std::string &file);
int destroyLuaThread(const std::string &file, lua_State *thread);
static void *the_alloc(void *ud, void *ptr, size_t osize, size_t nsize);
lua_State *baseState;
SmallBlockAllocator _sballoc;
};
#endif