@@ -101,90 +101,82 @@ void SafeDelete(ILuaValue* value)
101
101
102
102
void FillValue (GarrysMod::Lua::ILuaBase* LUA, ILuaValue* val, int iStackPos, int type)
103
103
{
104
- if (type == GarrysMod::Lua::Type::Number)
104
+ LUA_Vector* vec;
105
+ LUA_Angle* ang;
106
+ LUA_File* file;
107
+ LUA_File* copy;
108
+ std::unordered_map<ILuaValue*, ILuaValue*> tbl;
109
+ switch (type)
105
110
{
106
- val->type = type;
107
- val->number = LUA->GetNumber (iStackPos);
108
- } else if (type == GarrysMod::Lua::Type::Bool)
109
- {
110
- val->type = type;
111
- val->number = LUA->GetBool (iStackPos) ? 1 : 0 ;
112
- } else if (type == GarrysMod::Lua::Type::String)
113
- {
114
- val->type = type;
115
- val->string = LUA->GetString (iStackPos);
116
- } else if (type == GarrysMod::Lua::Type::Entity)
117
- {
118
- // val->type = type;
119
- // val->number = ((CBaseEntity*)ILUA->GetObject(3)->GetEntity())->edict()->m_EdictIndex;
120
- } else if (type == GarrysMod::Lua::Type::Vector)
121
- {
122
- val->type = type;
123
- if (ThreadInMainThread ())
124
- {
125
- const Vector& vec = LUA->GetVector (iStackPos);
126
- val->x = vec.x ;
127
- val->y = vec.y ;
128
- val->z = vec.z ;
129
- } else {
130
- LUA_Vector* vec = Vector_Get (LUA, iStackPos);
111
+ case GarrysMod::Lua::Type::Number:
112
+ val->type = type;
113
+ val->number = LUA->GetNumber (iStackPos);
114
+ return ;
115
+ case GarrysMod::Lua::Type::Bool:
116
+ val->type = type;
117
+ val->number = LUA->GetBool (iStackPos) ? 1 : 0 ;
118
+ return ;
119
+ case GarrysMod::Lua::Type::String:
120
+ val->type = type;
121
+ val->string = LUA->GetString (iStackPos);
122
+ return ;
123
+ case GarrysMod::Lua::Type::Entity:
124
+ // val->type = type;
125
+ // val->number = ((CBaseEntity*)ILUA->GetObject(3)->GetEntity())->edict()->m_EdictIndex;
126
+ return ;
127
+ case GarrysMod::Lua::Type::Vector:
128
+ val->type = type;
129
+ vec = Vector_Get (LUA, iStackPos);
131
130
val->x = vec->x ;
132
131
val->y = vec->y ;
133
132
val->z = vec->z ;
134
- }
135
- } else if (type == GarrysMod::Lua::Type::Angle)
136
- {
137
- val->type = type;
138
- if (ThreadInMainThread ())
139
- {
140
- const QAngle& ang = LUA->GetAngle (iStackPos);
141
- val->x = ang.x ;
142
- val->y = ang.y ;
143
- val->z = ang.z ;
144
- } else {
145
- LUA_Angle* ang = Angle_Get (LUA, iStackPos);
133
+ return ;
134
+ case GarrysMod::Lua::Type::Angle:
135
+ val->type = type;
136
+ ang = Angle_Get (LUA, iStackPos);
146
137
val->x = ang->x ;
147
138
val->y = ang->y ;
148
139
val->z = ang->z ;
149
- }
150
- } else if (type == GarrysMod::Lua::Type::Table)
151
- {
152
- val->type = type;
153
- std::unordered_map<ILuaValue*, ILuaValue*> tbl;
140
+ return ;
141
+ case GarrysMod::Lua::Type::Table:
142
+ val->type = type;;
154
143
155
- LUA->Push (iStackPos);
156
- LUA->PushNil ();
157
- while (LUA->Next (-2 )) {
158
- LUA->Push (-2 );
144
+ LUA->Push (iStackPos);
145
+ LUA->PushNil ();
146
+ while (LUA->Next (-2 )) {
147
+ LUA->Push (-2 );
159
148
160
- ILuaValue* key = new ILuaValue;
161
- FillValue (LUA, key, -1 , LUA->GetType (-1 ));
149
+ ILuaValue* key = new ILuaValue;
150
+ FillValue (LUA, key, -1 , LUA->GetType (-1 ));
162
151
163
- ILuaValue* new_val = new ILuaValue;
164
- FillValue (LUA, new_val, -2 , LUA->GetType (-2 ));
152
+ ILuaValue* new_val = new ILuaValue;
153
+ FillValue (LUA, new_val, -2 , LUA->GetType (-2 ));
165
154
166
- tbl[key] = new_val;
155
+ tbl[key] = new_val;
167
156
168
- LUA->Pop (2 );
169
- }
170
- LUA->Pop (1 );
157
+ LUA->Pop (2 );
158
+ }
159
+ LUA->Pop (1 );
171
160
172
- val->tbl = tbl;
173
- } else if (type == GarrysMod::Lua::Type::File)
174
- {
175
- if (ThreadInMainThread ()) // We cannot push a File from GMod to our module.
176
- {
161
+ val->tbl = tbl;
177
162
return ;
178
- }
163
+ case GarrysMod::Lua::Type::File:
164
+ if (ThreadInMainThread ()) // We cannot push a File from GMod to our module.
165
+ {
166
+ return ;
167
+ }
179
168
180
- LUA_File* file = File_Get (LUA, iStackPos);
181
- LUA_File* copy = new LUA_File;
182
- copy->fileMode = file->fileMode ;
183
- copy->filename = file->filename ;
184
- copy->path = file->path ;
185
- // copy->handle = file->handle // Should we really share the handle?
186
- val->type = type;
187
- val->data = copy;
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;
177
+ return ;
178
+ default :
179
+ return ;
188
180
}
189
181
}
190
182
@@ -336,22 +328,4 @@ std::string ToPath(std::string path)
336
328
}
337
329
338
330
return path;
339
- }
340
-
341
- ILuaValue* CreateValue (int value)
342
- {
343
- ILuaValue* val = new ILuaValue;
344
- val->type = GarrysMod::Lua::Type::Number;
345
- val->number = value;
346
-
347
- return val;
348
- }
349
-
350
- ILuaValue* CreateValue (const char * value)
351
- {
352
- ILuaValue* val = new ILuaValue;
353
- val->type = GarrysMod::Lua::Type::String;
354
- val->string = value;
355
-
356
- return val;
357
331
}
0 commit comments