Skip to content

Commit 7fcc6c0

Browse files
committed
Move vars into their cases back
1 parent dcfe492 commit 7fcc6c0

File tree

1 file changed

+40
-37
lines changed

1 file changed

+40
-37
lines changed

source/lua_utils.cpp

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,6 @@ void SafeDelete(ILuaValue* value)
101101

102102
void FillValue(GarrysMod::Lua::ILuaBase* LUA, ILuaValue* val, int iStackPos, int type)
103103
{
104-
LUA_Vector* vec;
105-
LUA_Angle* ang;
106-
LUA_File* file;
107-
LUA_File* copy;
108-
std::unordered_map<ILuaValue*, ILuaValue*> tbl;
109104
switch(type)
110105
{
111106
case GarrysMod::Lua::Type::Number:
@@ -125,55 +120,63 @@ void FillValue(GarrysMod::Lua::ILuaBase* LUA, ILuaValue* val, int iStackPos, int
125120
//val->number = ((CBaseEntity*)ILUA->GetObject(3)->GetEntity())->edict()->m_EdictIndex;
126121
return;
127122
case GarrysMod::Lua::Type::Vector:
128-
val->type = type;
129-
vec = Vector_Get(LUA, iStackPos);
130-
val->x = vec->x;
131-
val->y = vec->y;
132-
val->z = vec->z;
123+
{
124+
val->type = type;
125+
LUA_Vector* vec = Vector_Get(LUA, iStackPos);
126+
val->x = vec->x;
127+
val->y = vec->y;
128+
val->z = vec->z;
129+
}
133130
return;
134131
case GarrysMod::Lua::Type::Angle:
135-
val->type = type;
136-
ang = Angle_Get(LUA, iStackPos);
137-
val->x = ang->x;
138-
val->y = ang->y;
139-
val->z = ang->z;
132+
{
133+
val->type = type;
134+
LUA_Angle* ang = Angle_Get(LUA, iStackPos);
135+
val->x = ang->x;
136+
val->y = ang->y;
137+
val->z = ang->z;
138+
}
140139
return;
141140
case GarrysMod::Lua::Type::Table:
142-
val->type = type;;
141+
{
142+
val->type = type;
143+
std::unordered_map<ILuaValue*, ILuaValue*> tbl;
144+
LUA->Push(iStackPos);
145+
LUA->PushNil();
146+
while (LUA->Next(-2)) {
147+
LUA->Push(-2);
143148

144-
LUA->Push(iStackPos);
145-
LUA->PushNil();
146-
while (LUA->Next(-2)) {
147-
LUA->Push(-2);
149+
ILuaValue* key = new ILuaValue;
150+
FillValue(LUA, key, -1, LUA->GetType(-1));
148151

149-
ILuaValue* key = new ILuaValue;
150-
FillValue(LUA, key, -1, LUA->GetType(-1));
152+
ILuaValue* new_val = new ILuaValue;
153+
FillValue(LUA, new_val, -2, LUA->GetType(-2));
151154

152-
ILuaValue* new_val = new ILuaValue;
153-
FillValue(LUA, new_val, -2, LUA->GetType(-2));
155+
tbl[key] = new_val;
154156

155-
tbl[key] = new_val;
157+
LUA->Pop(2);
158+
}
159+
LUA->Pop(1);
156160

157-
LUA->Pop(2);
161+
val->tbl = tbl;
158162
}
159-
LUA->Pop(1);
160-
161-
val->tbl = tbl;
162163
return;
163164
case GarrysMod::Lua::Type::File:
164165
if (ThreadInMainThread()) // We cannot push a File from GMod to our module.
165166
{
166167
return;
167168
}
168169

169-
file = File_Get(LUA, iStackPos);
170-
copy = new LUA_File;
171-
copy->fileMode = file->fileMode;
172-
copy->filename = file->filename;
173-
copy->path = file->path;
174-
//copy->handle = file->handle // Should we really share the handle?
175-
val->type = type;
176-
val->data = copy;
170+
{
171+
LUA_File* file = File_Get(LUA, iStackPos);
172+
LUA_File* copy = new LUA_File;
173+
copy->fileMode = file->fileMode;
174+
copy->filename = file->filename;
175+
copy->path = file->path;
176+
//copy->handle = file->handle // Should we really share the handle?
177+
val->type = type;
178+
val->data = copy;
179+
}
177180
return;
178181
default:
179182
return;

0 commit comments

Comments
 (0)