Skip to content

Commit de63892

Browse files
isolate lua RString use and remove it
1 parent c141e20 commit de63892

12 files changed

+1070
-385
lines changed

src/LuaBinding.cpp

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include "LuaBinding.h"
33
#include "LuaReference.h"
44
#include "RageUtil.h"
5-
#include "Foreach.h"
65

76
#include "SubscriptionManager.h"
87
static SubscriptionManager<LuaBinding> m_Subscribers;
@@ -11,15 +10,17 @@ namespace
1110
{
1211
void RegisterTypes( lua_State *L )
1312
{
14-
if( m_Subscribers.m_pSubscribers == NULL )
13+
if( m_Subscribers.m_pSubscribers == nullptr )
1514
return;
1615

1716
/* Register base classes first. */
18-
map<RString, LuaBinding *> mapToRegister;
19-
FOREACHS( LuaBinding*, *m_Subscribers.m_pSubscribers, p )
20-
mapToRegister[(*p)->GetClassName()] = (*p);
17+
std::map<std::string, LuaBinding *> mapToRegister;
18+
for (auto *p: *m_Subscribers.m_pSubscribers)
19+
{
20+
mapToRegister[p->GetClassName()] = p;
21+
}
2122

22-
set<RString> setRegisteredAlready;
23+
std::set<std::string> setRegisteredAlready;
2324

2425
while( !mapToRegister.empty() )
2526
{
@@ -32,8 +33,8 @@ namespace
3233
{
3334
break;
3435
}
35-
RString sBase = pBinding->GetBaseClassName();
36-
map<RString, LuaBinding *>::const_iterator it = mapToRegister.find(sBase);
36+
std::string sBase = pBinding->GetBaseClassName();
37+
auto it = mapToRegister.find(sBase);
3738
if( it != mapToRegister.end() )
3839
{
3940
pBinding = it->second;
@@ -75,7 +76,7 @@ void LuaBinding::Register( lua_State *L )
7576
int methods = lua_gettop( L );
7677

7778
/* Create a metatable for the userdata objects. */
78-
luaL_newmetatable( L, GetClassName() );
79+
luaL_newmetatable( L, GetClassName().c_str() );
7980
int metatable = lua_gettop( L );
8081

8182
// We use the metatable to determine the type of the table, so don't
@@ -101,34 +102,34 @@ void LuaBinding::Register( lua_State *L )
101102
// to the base class.
102103
if( IsDerivedClass() )
103104
{
104-
lua_getfield( L, LUA_GLOBALSINDEX, GetBaseClassName() );
105+
lua_getfield( L, LUA_GLOBALSINDEX, GetBaseClassName().c_str() );
105106
lua_setfield( L, methods_metatable, "__index" );
106107

107-
lua_pushstring( L, GetBaseClassName() );
108+
lua_pushstring( L, GetBaseClassName().c_str() );
108109
lua_setfield( L, metatable, "base" );
109110
}
110111

111-
lua_pushstring( L, GetClassName() );
112+
lua_pushstring( L, GetClassName().c_str() );
112113
lua_setfield( L, methods_metatable, "class" );
113114

114-
lua_pushstring( L, GetClassName() );
115+
lua_pushstring( L, GetClassName().c_str() );
115116
LuaHelpers::PushValueFunc( L, 1 );
116117
lua_setfield( L, metatable, "__type" ); // for luaL_pushtype
117118

118119
{
119120
lua_newtable( L );
120121
int iHeirarchyTable = lua_gettop( L );
121122

122-
RString sClass = GetClassName();
123+
std::string sClass = GetClassName();
123124
int iIndex = 0;
124125
while( !sClass.empty() )
125126
{
126-
lua_pushstring( L, sClass );
127+
lua_pushstring( L, sClass.c_str() );
127128
lua_pushinteger( L, iIndex );
128129
lua_rawset( L, iHeirarchyTable );
129130
++iIndex;
130131

131-
luaL_getmetatable( L, sClass );
132+
luaL_getmetatable( L, sClass.c_str() );
132133
ASSERT( !lua_isnil(L, -1) );
133134
lua_getfield( L, -1, "base" );
134135

@@ -155,11 +156,11 @@ void LuaBinding::Register( lua_State *L )
155156
// types (eg. "Actor.x(GAMESTATE, 10)"), which will crash or cause corruption.
156157
// #define FAST_LUA
157158

158-
void LuaBinding::CreateMethodsTable( lua_State *L, const RString &sName )
159+
void LuaBinding::CreateMethodsTable( lua_State *L, const std::string &sName )
159160
{
160161
lua_newtable( L );
161162
lua_pushvalue( L, -1 );
162-
lua_setfield( L, LUA_GLOBALSINDEX, sName );
163+
lua_setfield( L, LUA_GLOBALSINDEX, sName.c_str() );
163164
}
164165

165166
int LuaBinding::PushEqual( lua_State *L )
@@ -217,7 +218,7 @@ bool LuaBinding::Equal( lua_State *L )
217218
* Get a userdata, and check that it's either szType or a type
218219
* derived from szType, by checking the heirarchy table.
219220
*/
220-
bool LuaBinding::CheckLuaObjectType( lua_State *L, int iArg, const char *szType )
221+
bool LuaBinding::CheckLuaObjectType( lua_State *L, int iArg, std::string const &szType )
221222
{
222223
#if defined(FAST_LUA)
223224
return true;
@@ -233,7 +234,7 @@ bool LuaBinding::CheckLuaObjectType( lua_State *L, int iArg, const char *szType
233234
return false;
234235
}
235236

236-
lua_getfield( L, -1, szType );
237+
lua_getfield( L, -1, szType.c_str() );
237238
bool bRet = !lua_isnil( L, -1 );
238239
lua_pop( L, 2 );
239240

@@ -255,7 +256,7 @@ static void GetGlobalTable( Lua *L )
255256
/* The object is on the stack. It's either a table or a userdata.
256257
* If needed, associate the metatable; if a table, also add it to
257258
* the userdata table. */
258-
void LuaBinding::ApplyDerivedType( Lua *L, const RString &sClassName, void *pSelf )
259+
void LuaBinding::ApplyDerivedType( Lua *L, const std::string &sClassName, void *pSelf )
259260
{
260261
int iTable = lua_gettop( L );
261262

@@ -290,14 +291,14 @@ void LuaBinding::ApplyDerivedType( Lua *L, const RString &sClassName, void *pSel
290291
lua_settop( L, iTable );
291292
}
292293

293-
luaL_getmetatable( L, sClassName );
294+
luaL_getmetatable( L, sClassName.c_str() );
294295
lua_setmetatable( L, iTable );
295296
}
296297

297298
#include "RageUtil_AutoPtr.h"
298299
REGISTER_CLASS_TRAITS( LuaClass, new LuaClass(*pCopy) )
299300

300-
void *LuaBinding::GetPointerFromStack( Lua *L, const RString &sType, int iArg )
301+
void *LuaBinding::GetPointerFromStack( Lua *L, const std::string &sType, int iArg )
301302
{
302303
iArg = LuaHelpers::AbsIndex( L, iArg );
303304

@@ -322,7 +323,7 @@ void *LuaBinding::GetPointerFromStack( Lua *L, const RString &sType, int iArg )
322323
return *pData;
323324
}
324325
else
325-
return NULL;
326+
return nullptr;
326327
}
327328

328329
/* Tricky: when an instance table is copied, we want to do a deep
@@ -354,7 +355,7 @@ LuaClass &LuaClass::operator=( const LuaClass &cpy )
354355

355356
LuaClass::~LuaClass()
356357
{
357-
if( LUA == NULL )
358+
if( LUA == nullptr )
358359
return;
359360

360361
Lua *L = LUA->Get();
@@ -394,7 +395,7 @@ float FArgGTEZero(lua_State* L, int index)
394395
/*
395396
* (c) 2005 Glenn Maynard
396397
* All rights reserved.
397-
*
398+
*
398399
* Permission is hereby granted, free of charge, to any person obtaining a
399400
* copy of this software and associated documentation files (the
400401
* "Software"), to deal in the Software without restriction, including
@@ -404,7 +405,7 @@ float FArgGTEZero(lua_State* L, int index)
404405
* copyright notice(s) and this permission notice appear in all copies of
405406
* the Software and that both the above copyright notice(s) and this
406407
* permission notice appear in supporting documentation.
407-
*
408+
*
408409
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
409410
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
410411
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF

0 commit comments

Comments
 (0)