Make Lua type checks optional. They add a lot of overhead to Lua dispatches.
This commit is contained in:
@@ -2,6 +2,12 @@
|
||||
#include "LuaBinding.h"
|
||||
#include "RageUtil.h"
|
||||
|
||||
// If defined, type checks for functions will be skipped. These add
|
||||
// up and can become expensive (performed for every function dispatch),
|
||||
// but without them it's possible to call functions on incompatible
|
||||
// types (eg. "Actor.x(GAMESTATE, 10)"), which will crash or cause corruption.
|
||||
// #define FAST_LUA
|
||||
|
||||
void CreateMethodsTable( lua_State *L, const CString &sName )
|
||||
{
|
||||
lua_pushlstring( L, sName.data(), sName.size() );
|
||||
@@ -20,8 +26,13 @@ void CreateMethodsTable( lua_State *L, const CString &sName )
|
||||
* Get a userdata, and check that it's either szType or a type
|
||||
* derived from szType, by walking the __index chain.
|
||||
*/
|
||||
bool CheckLuaObjectType( lua_State *L, int narg, const char *szType )
|
||||
bool CheckLuaObjectType( lua_State *L, int narg, const char *szType, bool bOptional )
|
||||
{
|
||||
#if defined(FAST_LUA)
|
||||
if( bOptional )
|
||||
return true;
|
||||
#endif
|
||||
|
||||
ASSERT_M( narg > 0, ssprintf("%i", narg) ); // negative offsets not supported
|
||||
|
||||
int iTop = lua_gettop(L);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
class LuaReference;
|
||||
|
||||
void CreateMethodsTable( lua_State *L, const CString &szName );
|
||||
bool CheckLuaObjectType( lua_State *L, int narg, const char *szType );
|
||||
bool CheckLuaObjectType( lua_State *L, int narg, const char *szType, bool bOptional=false );
|
||||
void *GetUserdataFromGlobalTable( Lua *L, const char *szType, int iArg );
|
||||
void ApplyDerivedType( Lua *L, const CString &sClassname, void *pSelf );
|
||||
|
||||
@@ -96,7 +96,7 @@ public:
|
||||
// Get userdata from the Lua stack and return a pointer to T object.
|
||||
static T *check( lua_State *L, int narg, bool bIsSelf = false )
|
||||
{
|
||||
if( !CheckLuaObjectType(L, narg, m_sClassName) )
|
||||
if( !CheckLuaObjectType(L, narg, m_sClassName, true) )
|
||||
{
|
||||
if( bIsSelf )
|
||||
luaL_typerror( L, narg, m_sClassName );
|
||||
|
||||
Reference in New Issue
Block a user