[PATCH] [script] atan and substring
Richard
mawr8 at cs.man.ac.uk
Wed Mar 10 08:42:52 PST 2010
Just a couple of script bindings. The single parameter atan function and a
substring function to flesh the string library out a bit. I wasn't sure if
it should finish with an error or finish with what it's already made if it
reached the end of the string while in the copy section.
diff --git a/src/plugins/splash/script/script-lib-math.c
b/src/plugins/splash/script/script-lib-math.c
index 383fe46..f614b18 100644
--- a/src/plugins/splash/script/script-lib-math.c
+++ b/src/plugins/splash/script/script-lib-math.c
@@ -85,6 +85,12 @@ script_lib_math_data_t *script_lib_math_setup
(script_state_t *state)
"value",
NULL);
script_add_native_function (math_hash,
+ "ATan",
+ script_lib_math_double_from_double_function,
+ atan,
+ "value",
+ NULL);
+ script_add_native_function (math_hash,
"ATan2",
script_lib_math_double_from_double_double_function,
atan2,
diff --git a/src/plugins/splash/script/script-lib-string.c
b/src/plugins/splash/script/script-lib-string.c
index 833a377..90c463b 100644
--- a/src/plugins/splash/script/script-lib-string.c
+++ b/src/plugins/splash/script/script-lib-string.c
@@ -62,6 +62,41 @@ static script_return_t script_lib_string_char_at
(script_state_t *state,
return script_return_obj(script_obj_new_string (charstring));
}
+static script_return_t script_lib_string_substring (script_state_t *state,
+ void
*user_data)
+{
+ char *text = script_obj_as_string (state->this);
+ int start = script_obj_hash_get_number (state->local, "start");
+ int end = script_obj_hash_get_number (state->local, "end");
+ int text_count, substring_count;
+ char substring [end-start+1];
+
+ if (!text || start < 0 || end < start)
+ {
+ free (text);
+ return script_return_obj_null ();
+ }
+ for (text_count = 0; text_count < start; text_count++)
+ {
+ if (text[text_count] == '\0')
+ {
+ free (text);
+ return script_return_obj(script_obj_new_string (""));
+ }
+ }
+ for (text_count = start, substring_count = 0; text_count < end;
text_count++, substring_count++)
+ {
+ if (text[text_count] == '\0')
+ {
+ break;
+ }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/plymouth/attachments/20100310/23dd2c0f/attachment.htm>
More information about the plymouth
mailing list