Beispiel #1
0
/*
* Given an ActionScript object, push it onto the Lua stack as a Lua native
* type if a primitive class (String, Number, Boolean, int, null).
* If object is not convertible to native Lua value, do not push anything
* (and return 0).
*
* WARNING: It important that this function does not touch
*          non-primitive values (like Arrays). If this will be changed,
*          optional primitive autoconversion logic will break.
*/
int push_as3_to_lua_stack_if_convertible(lua_State * L, AS3_Val val)
{
  LCALL(L, stack);

#ifdef DO_SPAM
  SPAM(("push_as3_to_lua_stack_if_convertible(): begin: value, type"));
  AS3_Trace(val);
  AS3_Trace(
      AS3_Call(
          getQualifiedClassName_method, NULL, AS3_Array("AS3ValType", val)
        )
    );
#endif /* DO_SPAM */

  if (AS3_InstanceOf(val, Number_class))
  {
    lua_pushnumber(L, AS3_NumberValue(val));
  }
  else if (AS3_InstanceOf(val, int_class))
  {
    lua_pushinteger(L, AS3_IntValue(val));
  }
  else if (AS3_InstanceOf(val, String_class))
  {
    size_t length = 0;
    AS3_Malloced_Str str = get_string_bytes(val, &length);
    lua_pushlstring(L, str, length);
    free(str);
  }
  else if (AS3_InstanceOf(val, Boolean_class))
  {
    lua_pushboolean(L, AS3_IntValue(val));
  }
  else if (val == AS3_Undefined())
  {
    lua_pushnil(L);
  }
  else if (is_null(val))
  {
    lua_pushnil(L);
  }
  else
  {
    SPAM(("push_as3_to_lua_stack_if_convertible(): not convertible"));
    LRETURN(L, stack, 0);
  }

  SPAM(("push_as3_to_lua_stack_if_convertible(): end"));

  LRETURN(L, stack, 1);
}
Beispiel #2
0
AS3_Val initializeFog( void* self, AS3_Val args )
{
	Fog * fog;

	AS3_Val color;

	double a, r, g, b, density, start, end;

	int mode;

	AS3_ArrayValue( args, "AS3ValType, DoubleType, DoubleType, DoubleType, IntType", & color, & start, & end, & density, & mode );

	r = AS3_NumberValue( AS3_GetS( color, "redMultiplier" ) );
	g = AS3_NumberValue( AS3_GetS( color, "greenMultiplier" ) );
	b = AS3_NumberValue( AS3_GetS( color, "blueMultiplier" ) );
	a = AS3_NumberValue( AS3_GetS( color, "alphaMultiplier" ) );

	fog = newFog( newColorValue( (float)r, (float)g, (float)b, (float)a ), (float)start, (float)end, (float)density, mode );

	AS3_Release( color );

	return AS3_Array( "PtrType, PtrType, PtrType, PtrType, PtrType, PtrType", fog, fog->global, & fog->start, & fog->end, & fog->density, & fog->mode );
}
Beispiel #3
0
AS3_Val initializeMaterial( void* self, AS3_Val args )
{
	Material * material;

	AS3_Val ambient, diffuse, specular, emissive;

	double a_a, a_r, a_g, a_b, d_a, d_r, d_g, d_b, s_a, s_r, s_g, s_b, e_a, e_r, e_g, e_b, power;

	AS3_ArrayValue( args, "AS3ValType, AS3ValType, AS3ValType, AS3ValType, DoubleType", &ambient, &diffuse, &specular, &emissive, &power );

	a_r = AS3_NumberValue( AS3_GetS( ambient, "redMultiplier" ) );
	a_g = AS3_NumberValue( AS3_GetS( ambient, "greenMultiplier" ) );
	a_b = AS3_NumberValue( AS3_GetS( ambient, "blueMultiplier" ) );
	a_a = AS3_NumberValue( AS3_GetS( ambient, "alphaMultiplier" ) );

	d_r = AS3_NumberValue( AS3_GetS( diffuse, "redMultiplier" ) );
	d_g = AS3_NumberValue( AS3_GetS( diffuse, "greenMultiplier" ) );
	d_b = AS3_NumberValue( AS3_GetS( diffuse, "blueMultiplier" ) );
	d_a = AS3_NumberValue( AS3_GetS( diffuse, "alphaMultiplier" ) );

	s_r = AS3_NumberValue( AS3_GetS( specular, "redMultiplier" ) );
	s_g = AS3_NumberValue( AS3_GetS( specular, "greenMultiplier" ) );
	s_b = AS3_NumberValue( AS3_GetS( specular, "blueMultiplier" ) );
	s_a = AS3_NumberValue( AS3_GetS( specular, "alphaMultiplier" ) );

	e_r = AS3_NumberValue( AS3_GetS( emissive, "redMultiplier" ) );
	e_g = AS3_NumberValue( AS3_GetS( emissive, "greenMultiplier" ) );
	e_b = AS3_NumberValue( AS3_GetS( emissive, "blueMultiplier" ) );
	e_a = AS3_NumberValue( AS3_GetS( emissive, "alphaMultiplier" ) );

	material = newMaterial( newColor888( (BYTE)(a_r * 255), (BYTE)(a_g * 255), (BYTE)(a_b * 255), (BYTE)(a_a * 255) ),
							newColor888( (BYTE)(d_r * 255), (BYTE)(d_g * 255), (BYTE)(d_b * 255), (BYTE)(d_a * 255) ),
							newColor888( (BYTE)(s_r * 255), (BYTE)(s_g * 255), (BYTE)(s_b * 255), (BYTE)(s_a * 255) ),
							newColor888( (BYTE)(e_r * 255), (BYTE)(e_g * 255), (BYTE)(e_b * 255), (BYTE)(e_a * 255) ),
							power );

	AS3_Release( ambient );
	AS3_Release( diffuse );
	AS3_Release( specular );
	AS3_Release( emissive );

	return AS3_Array( "PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType", material, material->ambient, material->diffuse, material->specular, material->emissive, &material->power, &material->doubleSide );
}