2
2
#include " LuaBinding.h"
3
3
#include " LuaReference.h"
4
4
#include " RageUtil.h"
5
- #include " Foreach.h"
6
5
7
6
#include " SubscriptionManager.h"
8
7
static SubscriptionManager<LuaBinding> m_Subscribers;
@@ -11,15 +10,17 @@ namespace
11
10
{
12
11
void RegisterTypes ( lua_State *L )
13
12
{
14
- if ( m_Subscribers.m_pSubscribers == NULL )
13
+ if ( m_Subscribers.m_pSubscribers == nullptr )
15
14
return ;
16
15
17
16
/* 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
+ }
21
22
22
- set<RString > setRegisteredAlready;
23
+ std:: set<std::string > setRegisteredAlready;
23
24
24
25
while ( !mapToRegister.empty () )
25
26
{
@@ -32,8 +33,8 @@ namespace
32
33
{
33
34
break ;
34
35
}
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 );
37
38
if ( it != mapToRegister.end () )
38
39
{
39
40
pBinding = it->second ;
@@ -75,7 +76,7 @@ void LuaBinding::Register( lua_State *L )
75
76
int methods = lua_gettop ( L );
76
77
77
78
/* Create a metatable for the userdata objects. */
78
- luaL_newmetatable ( L, GetClassName () );
79
+ luaL_newmetatable ( L, GetClassName (). c_str () );
79
80
int metatable = lua_gettop ( L );
80
81
81
82
// We use the metatable to determine the type of the table, so don't
@@ -101,34 +102,34 @@ void LuaBinding::Register( lua_State *L )
101
102
// to the base class.
102
103
if ( IsDerivedClass () )
103
104
{
104
- lua_getfield ( L, LUA_GLOBALSINDEX, GetBaseClassName () );
105
+ lua_getfield ( L, LUA_GLOBALSINDEX, GetBaseClassName (). c_str () );
105
106
lua_setfield ( L, methods_metatable, " __index" );
106
107
107
- lua_pushstring ( L, GetBaseClassName () );
108
+ lua_pushstring ( L, GetBaseClassName (). c_str () );
108
109
lua_setfield ( L, metatable, " base" );
109
110
}
110
111
111
- lua_pushstring ( L, GetClassName () );
112
+ lua_pushstring ( L, GetClassName (). c_str () );
112
113
lua_setfield ( L, methods_metatable, " class" );
113
114
114
- lua_pushstring ( L, GetClassName () );
115
+ lua_pushstring ( L, GetClassName (). c_str () );
115
116
LuaHelpers::PushValueFunc ( L, 1 );
116
117
lua_setfield ( L, metatable, " __type" ); // for luaL_pushtype
117
118
118
119
{
119
120
lua_newtable ( L );
120
121
int iHeirarchyTable = lua_gettop ( L );
121
122
122
- RString sClass = GetClassName ();
123
+ std::string sClass = GetClassName ();
123
124
int iIndex = 0 ;
124
125
while ( !sClass .empty () )
125
126
{
126
- lua_pushstring ( L, sClass );
127
+ lua_pushstring ( L, sClass . c_str () );
127
128
lua_pushinteger ( L, iIndex );
128
129
lua_rawset ( L, iHeirarchyTable );
129
130
++iIndex;
130
131
131
- luaL_getmetatable ( L, sClass );
132
+ luaL_getmetatable ( L, sClass . c_str () );
132
133
ASSERT ( !lua_isnil (L, -1 ) );
133
134
lua_getfield ( L, -1 , " base" );
134
135
@@ -155,11 +156,11 @@ void LuaBinding::Register( lua_State *L )
155
156
// types (eg. "Actor.x(GAMESTATE, 10)"), which will crash or cause corruption.
156
157
// #define FAST_LUA
157
158
158
- void LuaBinding::CreateMethodsTable ( lua_State *L, const RString &sName )
159
+ void LuaBinding::CreateMethodsTable ( lua_State *L, const std::string &sName )
159
160
{
160
161
lua_newtable ( L );
161
162
lua_pushvalue ( L, -1 );
162
- lua_setfield ( L, LUA_GLOBALSINDEX, sName );
163
+ lua_setfield ( L, LUA_GLOBALSINDEX, sName . c_str () );
163
164
}
164
165
165
166
int LuaBinding::PushEqual ( lua_State *L )
@@ -217,7 +218,7 @@ bool LuaBinding::Equal( lua_State *L )
217
218
* Get a userdata, and check that it's either szType or a type
218
219
* derived from szType, by checking the heirarchy table.
219
220
*/
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 )
221
222
{
222
223
#if defined(FAST_LUA)
223
224
return true ;
@@ -233,7 +234,7 @@ bool LuaBinding::CheckLuaObjectType( lua_State *L, int iArg, const char *szType
233
234
return false ;
234
235
}
235
236
236
- lua_getfield ( L, -1 , szType );
237
+ lua_getfield ( L, -1 , szType. c_str () );
237
238
bool bRet = !lua_isnil ( L, -1 );
238
239
lua_pop ( L, 2 );
239
240
@@ -255,7 +256,7 @@ static void GetGlobalTable( Lua *L )
255
256
/* The object is on the stack. It's either a table or a userdata.
256
257
* If needed, associate the metatable; if a table, also add it to
257
258
* 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 )
259
260
{
260
261
int iTable = lua_gettop ( L );
261
262
@@ -290,14 +291,14 @@ void LuaBinding::ApplyDerivedType( Lua *L, const RString &sClassName, void *pSel
290
291
lua_settop ( L, iTable );
291
292
}
292
293
293
- luaL_getmetatable ( L, sClassName );
294
+ luaL_getmetatable ( L, sClassName . c_str () );
294
295
lua_setmetatable ( L, iTable );
295
296
}
296
297
297
298
#include " RageUtil_AutoPtr.h"
298
299
REGISTER_CLASS_TRAITS ( LuaClass, new LuaClass(*pCopy) )
299
300
300
- void *LuaBinding::GetPointerFromStack( Lua *L, const RString &sType , int iArg )
301
+ void *LuaBinding::GetPointerFromStack( Lua *L, const std::string &sType , int iArg )
301
302
{
302
303
iArg = LuaHelpers::AbsIndex ( L, iArg );
303
304
@@ -322,7 +323,7 @@ void *LuaBinding::GetPointerFromStack( Lua *L, const RString &sType, int iArg )
322
323
return *pData;
323
324
}
324
325
else
325
- return NULL ;
326
+ return nullptr ;
326
327
}
327
328
328
329
/* Tricky: when an instance table is copied, we want to do a deep
@@ -354,7 +355,7 @@ LuaClass &LuaClass::operator=( const LuaClass &cpy )
354
355
355
356
LuaClass::~LuaClass ()
356
357
{
357
- if ( LUA == NULL )
358
+ if ( LUA == nullptr )
358
359
return ;
359
360
360
361
Lua *L = LUA->Get ();
@@ -394,7 +395,7 @@ float FArgGTEZero(lua_State* L, int index)
394
395
/*
395
396
* (c) 2005 Glenn Maynard
396
397
* All rights reserved.
397
- *
398
+ *
398
399
* Permission is hereby granted, free of charge, to any person obtaining a
399
400
* copy of this software and associated documentation files (the
400
401
* "Software"), to deal in the Software without restriction, including
@@ -404,7 +405,7 @@ float FArgGTEZero(lua_State* L, int index)
404
405
* copyright notice(s) and this permission notice appear in all copies of
405
406
* the Software and that both the above copyright notice(s) and this
406
407
* permission notice appear in supporting documentation.
407
- *
408
+ *
408
409
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
409
410
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
410
411
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
0 commit comments