summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharlie Brej <cbrej@cs.man.ac.uk>2009-07-08 10:06:25 +0100
committerCharlie Brej <cbrej@cs.man.ac.uk>2009-07-08 10:06:25 +0100
commitfe35d3852f7a25f8f6a2032bff6e2bbddc7848ca (patch)
treee4d7e0ef3977597222e737a476e63d453f636313
parent10df16ec29ceb6ee7e93214bb84b6304752f18ea (diff)
[script] Add atan2 to the math library
-rw-r--r--src/plugins/splash/script/script-lib-math.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/plugins/splash/script/script-lib-math.c b/src/plugins/splash/script/script-lib-math.c
index 17070352..c698de0e 100644
--- a/src/plugins/splash/script/script-lib-math.c
+++ b/src/plugins/splash/script/script-lib-math.c
@@ -44,9 +44,18 @@ static script_return_t script_lib_math_float_from_float_function (script_state_t
float (*function)(float) = user_data;
float value = script_obj_hash_get_float (state->local, "value");
float reply_float = function (value);
- return (script_return_t) {
- SCRIPT_RETURN_TYPE_RETURN, script_obj_new_float (reply_float)
- };
+ return (script_return_t) {SCRIPT_RETURN_TYPE_RETURN, script_obj_new_float (reply_float)};
+}
+
+
+static script_return_t script_lib_math_float_from_float_float_function (script_state_t *state,
+ void *user_data)
+{
+ float (*function)(float, float) = user_data;
+ float value1 = script_obj_hash_get_float (state->local, "value_a");
+ float value2 = script_obj_hash_get_float (state->local, "value_b");
+ float reply_float = function (value1, value2);
+ return (script_return_t) {SCRIPT_RETURN_TYPE_RETURN, script_obj_new_float (reply_float)};
}
static script_return_t script_lib_math_int_from_float_function (script_state_t *state,
@@ -55,9 +64,7 @@ static script_return_t script_lib_math_int_from_float_function (script_state_t *
int (*function)(float) = user_data;
float value = script_obj_hash_get_float (state->local, "value");
int reply_int = function (value);
- return (script_return_t) {
- SCRIPT_RETURN_TYPE_RETURN, script_obj_new_int (reply_int)
- };
+ return (script_return_t) {SCRIPT_RETURN_TYPE_RETURN, script_obj_new_int (reply_int)};
}
static int float_to_int (float value)
@@ -88,6 +95,13 @@ script_lib_math_data_t *script_lib_math_setup (script_state_t *state)
"value",
NULL);
script_add_native_function (state->global,
+ "MathATan2",
+ script_lib_math_float_from_float_float_function,
+ atan2f,
+ "value_a",
+ "value_b",
+ NULL);
+ script_add_native_function (state->global,
"MathSqrt",
script_lib_math_float_from_float_function,
sqrtf,