]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
[script] Added a turn float to integer function to the math library
authorCharlie Brej <cbrej@cs.man.ac.uk>
Tue, 30 Jun 2009 15:53:21 +0000 (16:53 +0100)
committerCharlie Brej <cbrej@cs.man.ac.uk>
Tue, 30 Jun 2009 15:53:21 +0000 (16:53 +0100)
src/plugins/splash/script/script-lib-math.c

index 544b8f34ff74d906b4ce5b049fdeeaffc75c2e25..f10f50011bf7f290781a95203f57c07c9de525ec 100644 (file)
@@ -18,7 +18,7 @@
 #include "script-lib-math.string"
 
 
-static script_return script_lib_math_single_float_function (script_state* state, void* user_data)
+static script_return script_lib_math_float_from_float_function (script_state* state, void* user_data)
 {
  float (*function) (float) = user_data;
  script_obj* obj = script_obj_hash_get_element (state->local, "value");
@@ -30,14 +30,33 @@ static script_return script_lib_math_single_float_function (script_state* state,
  return (script_return){SCRIPT_RETURN_TYPE_RETURN, reply};
 }
 
+static script_return script_lib_math_int_from_float_function (script_state* state, void* user_data)
+{
+ int (*function) (float) = user_data;
+ script_obj* obj = script_obj_hash_get_element (state->local, "value");
+ script_obj* reply;
+ float reply_int = function(script_obj_as_float(obj));
+ script_obj_unref(obj);
+ reply = script_obj_new_int (reply_int);
+ return (script_return){SCRIPT_RETURN_TYPE_RETURN, reply};
+}
+
+
+
+static int float_to_int (float value)
+{
+ return (int) value;
+}
+
 script_lib_math_data_t* script_lib_math_setup(script_state *state)
 {
  script_lib_math_data_t* data = malloc(sizeof(script_lib_math_data_t));
  
- script_add_native_function (state->global, "MathCos", script_lib_math_single_float_function, cosf, "value", NULL);
- script_add_native_function (state->global, "MathSin", script_lib_math_single_float_function, sinf, "value", NULL);
- script_add_native_function (state->global, "MathTan", script_lib_math_single_float_function, tanf, "value", NULL);
- script_add_native_function (state->global, "MathSqrt",script_lib_math_single_float_function, sqrtf,"value", NULL);
+ script_add_native_function (state->global, "MathCos", script_lib_math_float_from_float_function, cosf,         "value", NULL);
+ script_add_native_function (state->global, "MathSin", script_lib_math_float_from_float_function, sinf,         "value", NULL);
+ script_add_native_function (state->global, "MathTan", script_lib_math_float_from_float_function, tanf,         "value", NULL);
+ script_add_native_function (state->global, "MathSqrt",script_lib_math_float_from_float_function, sqrtf,        "value", NULL);
+ script_add_native_function (state->global, "MathInt", script_lib_math_int_from_float_function,   float_to_int, "value", NULL);
  
  data->script_main_op = script_parse_string (script_lib_math_string);
  script_return ret = script_execute(state, data->script_main_op);