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 "LuaBinding.h"
|
||||||
#include "RageUtil.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 )
|
void CreateMethodsTable( lua_State *L, const CString &sName )
|
||||||
{
|
{
|
||||||
lua_pushlstring( L, sName.data(), sName.size() );
|
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
|
* Get a userdata, and check that it's either szType or a type
|
||||||
* derived from szType, by walking the __index chain.
|
* 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
|
ASSERT_M( narg > 0, ssprintf("%i", narg) ); // negative offsets not supported
|
||||||
|
|
||||||
int iTop = lua_gettop(L);
|
int iTop = lua_gettop(L);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
class LuaReference;
|
class LuaReference;
|
||||||
|
|
||||||
void CreateMethodsTable( lua_State *L, const CString &szName );
|
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 *GetUserdataFromGlobalTable( Lua *L, const char *szType, int iArg );
|
||||||
void ApplyDerivedType( Lua *L, const CString &sClassname, void *pSelf );
|
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.
|
// Get userdata from the Lua stack and return a pointer to T object.
|
||||||
static T *check( lua_State *L, int narg, bool bIsSelf = false )
|
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 )
|
if( bIsSelf )
|
||||||
luaL_typerror( L, narg, m_sClassName );
|
luaL_typerror( L, narg, m_sClassName );
|
||||||
|
|||||||
Reference in New Issue
Block a user