Added sprintf

This commit is contained in:
Robert MacGregor 2014-08-16 03:45:03 -04:00
parent 2f163fdd59
commit 09c3e57b6d
4 changed files with 42 additions and 16 deletions

View file

@ -17,3 +17,9 @@ This function did not exist before in Torque Script, it returns whether or not t
#### Player.isJumping()
This function did not exist before in Torque Script, it returns whether or not the Player is currently jumping.
#### sprintf(format, ...)
This function did not exist before in Torque Script. It returns a formatted string according to format with all variable
arguments up to a total of twenty filled in. Refer to C's sprintf for more information.
Note: Only %s should be used in the format as Torque Script passes all data around as strings.

View file

@ -25,8 +25,8 @@ bool conPlayerGetJettingState(SimObject *obj, S32 argc, const char* argv[]);
const char* conGrenadeProjectileGetPosition(SimObject *obj, S32 argc, const char* argv[]);
const char* conGrenadeProjectileGetVelocity(SimObject *obj, S32 argc, const char* argv[]);
// Projectile explode
// Projectile explode -------------------------------
bool conProjectileExplode(SimObject *obj, S32 argc, const char* argv[]);
// Tests Position Z
const char *conPlayerSetZ(SimObject *obj, S32 argc, const char *argv[]);
// General Commands ---------------------------------
const char* conSprintf(SimObject *obj, S32 argc, const char* argv[]);

View file

@ -18,5 +18,7 @@ extern "C"
Con::addMethodS("GrenadeProjectile", "getposition", &conGrenadeProjectileGetPosition,"Accurately gets the position of the GrenadeProjectile", 2, 2);
Con::addMethodS("GrenadeProjectile", "getvelocity", &conGrenadeProjectileGetVelocity,"Gets the velocity of the GrenadeProjectile", 2, 2);
Con::addMethodS(NULL, "sprintf", &conSprintf,"Formats a string. See the C sprintf.", 2, 20);
}
}

View file

@ -1,7 +1,7 @@
/**
*
*/
#include <LinkerAPI.h>
#include <DXAPI.h>
@ -13,18 +13,6 @@ const char *conGetAddress(SimObject *obj, S32 argc, const char *argv[])
return result;
}
const char *conPlayerSetZ(SimObject *obj, S32 argc, const char *argv[])
{
DX::Player test = DX::GetPlayerPointer(obj);
test.position_y = 100;
test.position_z = 300;
test.position_x = 500;
char result[256];
sprintf(result, "LOL");
return result;
}
bool conPlayerGetJumpingState(SimObject *obj, S32 argc, const char* argv[])
{
DX::Player operand = DX::GetPlayerPointer(obj);
@ -72,5 +60,35 @@ const char* conGrenadeProjectileGetVelocity(SimObject *obj, S32 argc, const char
DX::GrenadeProjectile grenade = DX::GetGrenadeProjectilePointer(obj);
sprintf_s<256>(result, "%f %f %f", grenade.velocity_x, grenade.velocity_y, grenade.velocity_z);
return result;
}
// General Commands ---------------------------------
#include <cstdarg>
#include <vector>
#include <string.h>
#define _crt_va_start(ap,v) ( ap = (va_list)_ADDRESSOF(v) + _INTSIZEOF(v) )
#define _crt_va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
#define _crt_va_end(ap) ( ap = (va_list)0 )
#define va_start _crt_va_start
#define va_arg _crt_va_arg
#define va_end _crt_va_end
const char* conSprintf(SimObject *obj, S32 argc, const char* argv[])
{
std::vector<const char*> input;
for (unsigned int i = 2; i < argc; i++)
input.push_back(argv[i]);
char result[256];
va_list variable_args = reinterpret_cast<va_list>(input.data());
//variable_args = (va_list)_ADDRESSOF(variable_args) + _INTSIZEOF(input.size() * 4);
vsprintf(result, argv[1], variable_args);
//va_end(variable_args);
return result;
}