Skip to content

Instantly share code, notes, and snippets.

@Kefta
Last active March 7, 2022 19:03
Show Gist options
  • Save Kefta/e34782f4622a6bc63262b42d9dee451d to your computer and use it in GitHub Desktop.
Save Kefta/e34782f4622a6bc63262b42d9dee451d to your computer and use it in GitHub Desktop.
LUA_FUNCTION( Vector_Serialize )
{
LUA->CheckType(1, GarrysMod::Lua::Type::Vector);
const Vector& vec = *LUA->GetUserType<Vector>(1, GarrysMod::Lua::Type::Vector);
const char* const separator = LUA->GetType(2) <= GarrysMod::Lua::Type::Nil
? LUA->CheckString(2) : " ";
LUA->PushFormattedString("%u%s%u%s%u", vec.x, separator, vec.y, separator, vec.z);
return 1;
}
LUA_FUNCTION( Angle_Serialize )
{
LUA->CheckType(1, GarrysMod::Lua::Type::Angle);
const QAngle& ang = *LUA->GetUserType<Angle>(1, GarrysMod::Lua::Type::Angle);
const char* const separator = LUA->GetType(2) <= GarrysMod::Lua::Type::Nil
? LUA->CheckString(2) : " ";
LUA->PushFormattedString("%u%s%u%s%u", ang.x, separator, ang.y, separator, ang.z);
return 1;
}
LUA_FUNCTION( Matrix_Serialize )
{
LUA->CheckType(1, GarrysMod::Lua::Type::Matrix);
const VMatrix& mat = *LUA->GetUserType(1, GarrysMod::Lua::Type::Matrix);
const char* const separator = LUA->GetType(2) <= GarrysMod::Lua::Type::Nil
? LUA->CheckString(2) : " ";
LUA->PushFormattedString("%u%s%u%s%u%s%u%s%u%s%u%s%u%s%u%s%u%s%u%s%u%s%u%s%u%s%u%s%u%s%u",
self->m[0][0], separator, self->m[0][1], separator, self->m[0][2], separator, self->m[0][3], separator,
self->m[1][0], separator, self->m[1][1], separator, self->m[1][2], separator, self->m[1][3], separator,
self->m[2][0], separator, self->m[2][1], separator, self->m[2][2], separator, self->m[2][3], separator,
self->m[3][0], separator, self->m[3][1], separator, self->m[3][2], separator, self->m[3][3]);
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment