Exemplo n.º 1
0
static int socket_error( SGS_CTX )
{
	int astext = 0, e = 0;
	SGSFN( "socket_error" );
	if( !sgs_LoadArgs( C, "|b", &astext ) )
		return 0;
	
	if( sgs_PushGlobal( C, SCKERRVN ) == SGS_SUCCESS )
		e = (int) sgs_GetInt( C, -1 );
	else if( !astext )
		sgs_PushInt( C, 0 );
	
	if( !astext )
		return 1;
	
#ifdef _WIN32
	{
		char buf[ 1024 ];
		DWORD numwr = FormatMessageA
		(
			FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, (DWORD) e,
			MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
			buf, 1024, NULL
		);
		if( !numwr )
			STDLIB_WARN( "failed to retrieve error message" )
		sgs_PushStringBuf( C, buf, (sgs_SizeVal) numwr );
	}
#else
	sgs_PushString( C, strerror( e ) );
#endif
	return 1;
}
Exemplo n.º 2
0
static int idbg_setstackitem( SGS_CTX )
{
	sgs_Bool full = 0;
	sgs_Int off, cnt;
	sgs_Variable* a, *b, *x, tmp;
	SGS_IDBG = (sgs_IDbg*) C->msg_ctx;
	
	SGSFN( "dbg_setstackitem" );
	if( !sgs_LoadArgs( C, "i?v|b", &off, &full ) )
		return 0;
	
	a = full ? C->stack_base : C->stack_base + D->stkoff;
	b = C->stack_base + D->stksize;
	cnt = b - a;
	if( off >= cnt || -off > cnt )
	{
		sgs_Msg( C, SGS_WARNING,
			"index %d out of bounds, count = %d\n", (int) off, (int) cnt );
		return 0;
	}
	
	x = off >= 0 ? a + off : b + off;
	tmp = *x;
	sgs_Acquire( C, &tmp );
	sgs_GetStackItem( C, 1, x );
	sgs_Release( C, &tmp );
	return 0;
}
Exemplo n.º 3
0
static int Bullet_CreateBoxShapeV3( SGS_CTX )
{
	float he[3] = {1,1,1};
	SGSFN( "Bullet_CreateBoxShapeV3" );
	if( !sgs_LoadArgs( C, "!x", sgs_ArgCheck_Vec3, he ) )
		return 0;
	SGS_CREATECLASS( C, NULL, BulletBoxShape, ( btVector3( he[0], he[1], he[2] ) ) );
	return 1;
}
Exemplo n.º 4
0
static int SS_EnableProfiler( SGS_CTX )
{
	SGSFN( "SS_EnableProfiler" );
	if( sgs_StackSize( C ) > 0 )
		GEnabledProfiler = sgs_GetInt( C, 0 );
	else
		GEnabledProfiler = 1;
	return 0;
}
Exemplo n.º 5
0
static int Bullet_CreateCapsuleShapeZ( SGS_CTX )
{
	float radius = 1.0f, height = 1.0f;
	SGSFN( "Bullet_CreateCapsuleShapeZ" );
	if( !sgs_LoadArgs( C, "ff", &radius, &height ) )
		return 0;
	SGS_CREATECLASS( C, NULL, BulletCapsuleShapeZ, ( radius, height ) );
	return 1;
}
Exemplo n.º 6
0
static int Bullet_CreateBoxShape( SGS_CTX )
{
	float he[3] = {1,1,1};
	SGSFN( "Bullet_CreateBoxShape" );
	if( !sgs_LoadArgs( C, "fff", he+0, he+1, he+2 ) )
		return 0;
	SGS_CREATECLASS( C, NULL, BulletBoxShape, ( btVector3( he[0], he[1], he[2] ) ) );
	return 1;
}
Exemplo n.º 7
0
static int Bullet_CreateSphereShape( SGS_CTX )
{
	float radius = 1.0f;
	SGSFN( "Bullet_CreateSphereShape" );
	if( !sgs_LoadArgs( C, "f", &radius ) )
		return 0;
	SGS_CREATECLASS( C, NULL, BulletSphereShape, ( radius ) );
	return 1;
}
Exemplo n.º 8
0
static int Bullet_CreateTriangleMesh( SGS_CTX )
{
	sgs_Bool i32 = 0, v4c = 1;
	SGSFN( "Bullet_CreateTriangleMesh" );
	if( !sgs_LoadArgs( C, "b|b", &i32, &v4c ) )
		return 0;
	SGS_CREATECLASS( C, NULL, BulletTriangleMesh, ( i32, v4c ) );
	return 1;
}
Exemplo n.º 9
0
static int Bullet_CreateTransform( SGS_CTX )
{
	float pos[3] = {0,0,0};
	SGSFN( "Bullet_CreateTransform" );
	if( !sgs_LoadArgs( C, "|!x", sgs_ArgCheck_Vec3, pos ) )
		return 0;
	SGS_CREATELITECLASS( C, NULL, BulletTransform, ( btTransform( btQuaternion::getIdentity(), btVector3( pos[0], pos[1], pos[2] ) ) ) );
	return 1;
}
Exemplo n.º 10
0
static int Bullet_CreateRigidBody( SGS_CTX )
{
	BulletRigidBodyCreationInfo* rbci;
	SGSFN( "Bullet_CreateRigidBody" );
	if( !sgs_LoadArgs( C, "!o", &BulletRigidBodyCreationInfo::_sgs_interface.iface, &rbci ) )
		return 0;
	SGS_CREATECLASS( C, NULL, BulletRigidBody, ( rbci ) );
	return 1;
}
Exemplo n.º 11
0
static int Bullet_CreateBVHTriangleMeshShape( SGS_CTX )
{
	sgs_Bool qbbc = 0, build = 1;
	SGSFN( "Bullet_CreateBVHTriangleMeshShape" );
	if( !sgs_LoadArgs( C, ">|bb", &qbbc, &build ) )
		return 0;
	BulletStridingMeshInterfaceHandle bsmih = sgs_GetVar<BulletStridingMeshInterfaceHandle>()( C, 0 );
	if( !bsmih.obj )
		return sgs_Msg( C, SGS_WARNING, "argument 1 must be a striding mesh interface object" );
	SGS_CREATECLASS( C, NULL, BulletBVHTriangleMeshShape, ( bsmih, qbbc, build ) );
	return 1;
}
Exemplo n.º 12
0
static int sgs_socket_gethostname( SGS_CTX )
{
	char buf[ 256 ];
	SGSFN( "socket_gethostname" );
	if( !sgs_LoadArgs( C, "." ) )
		return 0;
	if( !sockassert( C, gethostname( buf, 256 ) == 0 ) )
		STDLIB_WARN( "failed to get host name" )
	buf[ 256-1 ] = 0;
	sgs_PushString( C, buf );
	return 1;
}
Exemplo n.º 13
0
static int sgs_socket_getaddrinfo( SGS_CTX )
{
	sgs_StkIdx sz0, sz1;
	struct addrinfo hints, *list = NULL, *pp;
	char *addr, *servport;
	sgs_Int socktype = SOCK_STREAM, af = AF_UNSPEC;
	
	SGSFN( "socket_getaddrinfo" );
	/* address, port, socktype, address_family */
	if( !sgs_LoadArgs( C, "ss|ii", &addr, &servport, &socktype, &af ) )
		return 0;
	
	memset( &hints, 0, sizeof(hints) );
	hints.ai_socktype = (int) socktype;
	hints.ai_family = (int) af;
	
	if( !sockassert( C, getaddrinfo( addr, servport, &hints, &list ) == 0 ) )
		STDLIB_WARN( "failed to get address info" )
	
	pp = list;
	sz0 = sgs_StackSize( C );
	while( pp )
	{
		sz1 = sgs_StackSize( C );
		
		sgs_PushString( C, "flags" );
		sgs_PushInt( C, pp->ai_flags );
		sgs_PushString( C, "family" );
		sgs_PushInt( C, pp->ai_family );
		sgs_PushString( C, "socktype" );
		sgs_PushInt( C, pp->ai_socktype );
		sgs_PushString( C, "protocol" );
		sgs_PushInt( C, pp->ai_protocol );
		sgs_PushString( C, "canonname" );
		if( pp->ai_canonname )
			sgs_PushString( C, pp->ai_canonname );
		else
			sgs_PushNull( C );
		sgs_PushString( C, "addr" );
		push_sockaddr( C, (struct sockaddr_storage*) (void*) pp->ai_addr, pp->ai_addrlen );
		
		sgs_PushDict( C, sgs_StackSize( C ) - sz1 );
		pp = pp->ai_next;
	}
	freeaddrinfo( list );
	sgs_PushArray( C, sgs_StackSize( C ) - sz0 );
	return 1;
}
Exemplo n.º 14
0
static int sgs_socket_address( SGS_CTX )
{
	struct sockaddr_storage ss;
	char* buf;
	sgs_SizeVal bufsize;
	sgs_Int af;
	uint16_t port = 0;
	
	SGSFN( "socket_address" );
	if( !sgs_LoadArgs( C, "im|+w", &af, &buf, &bufsize, &port ) )
		return 0;
	
	if( af != AF_INET && af != AF_INET6 )
		STDLIB_WARN( "argument 1 (address family)"
			" must be either AF_INET or AF_INET6" )
	
	memset( &ss, 0, sizeof(ss) );
	
	ss.ss_family = (sa_family_t) af;
	port = htons( port );
	{
#ifdef _WIN32
		INT len = sizeof( ss );
		int res = sockassert( C, WSAStringToAddressA( buf, (int16_t) af,
			NULL, (struct sockaddr*) &ss, &len ) == 0 );
#else
		int res = sockassert( C, inet_pton( (int16_t) af, buf, &ss ) == 1 );
#endif
		if( !res )
			STDLIB_WARN( "failed to generate address from string" )
	}
	
	if( af == AF_INET )
	{
		struct sockaddr_in* sai = (struct sockaddr_in*) &ss;
		sai->sin_port = port;
	}
	else if( af == AF_INET6 )
	{
		struct sockaddr_in6* sai = (struct sockaddr_in6*) &ss;
		sai->sin6_port = port;
	}
	else
		STDLIB_WARN( "INTERNAL ERROR (unexpected AF value)" )
	
	push_sockaddr( C, &ss, sizeof(ss) );
	return 1;
}
Exemplo n.º 15
0
static int sgs_socket_address_frombytes( SGS_CTX )
{
	struct sockaddr_storage ss = {0};
	char* buf;
	sgs_SizeVal bufsize;
	sgs_Int af;
	uint16_t port = 0;
	
	SGSFN( "socket_address_frombytes" );
	if( !sgs_LoadArgs( C, "im|+w", &af, &buf, &bufsize, &port ) )
		return 0;
	
	if( af != AF_INET && af != AF_INET6 )
		STDLIB_WARN( "argument 1 (address family)"
			" must be either AF_INET or AF_INET6" )
	
	ss.ss_family = (sa_family_t) af;
	port = htons( port );
	if( af == AF_INET )
	{
		struct sockaddr_in* sai = (struct sockaddr_in*) &ss;
		if( bufsize != 4 )
			STDLIB_WARN( "argument 2 (buffer)"
				" must be 4 bytes long for an AF_INET address" )
		sai->sin_port = port;
		memcpy( &sai->sin_addr.s_addr, buf, 4 );
	}
	else if( af == AF_INET6 )
	{
		struct sockaddr_in6* sai = (struct sockaddr_in6*) &ss;
		if( bufsize != 16 )
			STDLIB_WARN( "argument 2 (buffer)"
				" must be 16 bytes long for an AF_INET address" )
		sai->sin6_port = port;
		memcpy( sai->sin6_addr.s6_addr, buf, 16 );
	}
	else
		STDLIB_WARN( "unsupported address family" );
	
	push_sockaddr( C, &ss, sizeof(ss) );
	return 1;
}
Exemplo n.º 16
0
static int socket_geterrnobyname( SGS_CTX )
{
	const char** ekt = socket_errno_key_table;
	char* str;
	
	SGSFN( "socket_geterrnobyname" );
	
	if( !sgs_LoadArgs( C, "s", &str ) )
		return 0;
	
	while( *ekt )
	{
		if( strcmp( *ekt, str ) == 0 )
		{
			sgs_PushInt( C, (int) (size_t) ekt[1] );
			return 1;
		}
		ekt += 2;
	}
	
	sgs_Msg( C, SGS_ERROR, "this socket errno value is unsupported on this platform" );
	return 0;
}
Exemplo n.º 17
0
static int idbg_stackitem( SGS_CTX )
{
	sgs_Bool full = 0;
	sgs_Int off, cnt;
	sgs_Variable* a, *b;
	SGS_IDBG = (sgs_IDbg*) C->msg_ctx;
	
	SGSFN( "dbg_stackitem" );
	if( !sgs_LoadArgs( C, "i|b", &off, &full ) )
		return 0;
	
	a = full ? C->stack_base : C->stack_base + D->stkoff;
	b = C->stack_base + D->stksize;
	cnt = b - a;
	if( off >= cnt || -off > cnt )
	{
		sgs_Msg( C, SGS_WARNING, 
			"index %d out of bounds, count = %d\n", (int) off, (int) cnt );
		return 0;
	}
	
	sgs_PushVariable( C, off >= 0 ? a + off : b + off );
	return 1;
}
Exemplo n.º 18
0
static int Bullet_CreateConvexHullShape( SGS_CTX )
{
	SGSFN( "Bullet_CreateConvexHullShape" );
	SGS_CREATECLASS( C, NULL, BulletConvexHullShape, () );
	return 1;
}
Exemplo n.º 19
0
static int Bullet_CreateRigidBodyCreationInfo( SGS_CTX )
{
	SGSFN( "Bullet_CreateRigidBodyCreationInfo" );
	SGS_CREATECLASS( C, NULL, BulletRigidBodyCreationInfo, () );
	return 1;
}
Exemplo n.º 20
0
static int Bullet_CreateWorld( SGS_CTX )
{
	SGSFN( "Bullet_CreateWorld" );
	SGS_CREATECLASS( C, NULL, BulletDynamicsWorld, () );
	return 1;
}
Exemplo n.º 21
0
static int Bullet_CreateGhostObject( SGS_CTX )
{
	SGSFN( "Bullet_CreateGhostObject" );
	SGS_CREATECLASS( C, NULL, BulletGhostObject, () );
	return 1;
}