script_lib_math_data_t *script_lib_math_setup (script_state_t *state) { script_lib_math_data_t *data = malloc (sizeof (script_lib_math_data_t)); srand ((int) ply_get_timestamp ()); script_obj_t *math_hash = script_obj_hash_get_element (state->global, "Math"); script_add_native_function (math_hash, "Cos", script_lib_math_double_from_double_function, cos, "value", NULL); script_add_native_function (math_hash, "Sin", script_lib_math_double_from_double_function, sin, "value", NULL); script_add_native_function (math_hash, "Tan", script_lib_math_double_from_double_function, tan, "value", NULL); script_add_native_function (math_hash, "ATan2", script_lib_math_double_from_double_double_function, atan2, "value_a", "value_b", NULL); script_add_native_function (math_hash, "Sqrt", script_lib_math_double_from_double_function, sqrt, "value", NULL); script_add_native_function (math_hash, "Int", script_lib_math_double_from_double_function, floor, "value", NULL); script_add_native_function (math_hash, "Random", script_lib_math_random, NULL, NULL); script_obj_unref (math_hash); data->script_main_op = script_parse_string (script_lib_math_string, "script-lib-math.script"); script_return_t ret = script_execute (state, data->script_main_op); script_obj_unref (ret.object); return data; }
void script_lib_plymouth_on_hide_message (script_state_t *state, script_lib_plymouth_data_t *data, const char *message) { script_obj_t *new_message_obj = script_obj_new_string (message); script_return_t ret = script_execute_object (state, data->script_hide_message_func, NULL, new_message_obj, NULL); script_obj_unref (new_message_obj); script_obj_unref (ret.object); }
void script_lib_plymouth_on_update_status (script_state_t *state, script_lib_plymouth_data_t *data, const char *new_status) { script_obj_t *new_status_obj = script_obj_new_string (new_status); script_return_t ret = script_execute_object (state, data->script_update_status_func, NULL, new_status_obj, NULL); script_obj_unref (new_status_obj); script_obj_unref (ret.object); }
void script_lib_plymouth_on_keyboard_input (script_state_t *state, script_lib_plymouth_data_t *data, const char *keyboard_input) { script_obj_t *keyboard_input_obj = script_obj_new_string (keyboard_input); script_return_t ret = script_execute_object (state, data->script_keyboard_input_func, NULL, keyboard_input_obj, NULL); script_obj_unref (keyboard_input_obj); script_obj_unref (ret.object); }
static bool start_script_animation (ply_boot_splash_plugin_t *plugin) { assert (plugin != NULL); plugin->script_state = script_state_new (plugin); plugin->script_image_lib = script_lib_image_setup (plugin->script_state, plugin->image_dir); plugin->script_sprite_lib = script_lib_sprite_setup (plugin->script_state, plugin->displays); plugin->script_plymouth_lib = script_lib_plymouth_setup (plugin->script_state, plugin->mode); plugin->script_math_lib = script_lib_math_setup (plugin->script_state); plugin->script_string_lib = script_lib_string_setup (plugin->script_state); ply_trace ("executing script file"); script_return_t ret = script_execute (plugin->script_state, plugin->script_main_op); script_obj_unref (ret.object); if (plugin->keyboard != NULL) ply_keyboard_add_input_handler (plugin->keyboard, (ply_keyboard_input_handler_t) on_keyboard_input, plugin); on_timeout (plugin); return true; }
void script_lib_plymouth_on_display_question (script_state_t *state, script_lib_plymouth_data_t *data, const char *prompt, const char *entry_text) { script_obj_t *prompt_obj = script_obj_new_string (prompt); script_obj_t *entry_text_obj = script_obj_new_string (entry_text); script_return_t ret = script_execute_object (state, data->script_display_question_func, NULL, prompt_obj, entry_text_obj, NULL); script_obj_unref (prompt_obj); script_obj_unref (entry_text_obj); script_obj_unref (ret.object); }
void script_lib_plymouth_on_display_password (script_state_t *state, script_lib_plymouth_data_t *data, const char *prompt, int bullets) { script_obj_t *prompt_obj = script_obj_new_string (prompt); script_obj_t *bullets_obj = script_obj_new_number (bullets); script_return_t ret = script_execute_object (state, data->script_display_password_func, NULL, prompt_obj, bullets_obj, NULL); script_obj_unref (prompt_obj); script_obj_unref (bullets_obj); script_obj_unref (ret.object); }
void script_lib_plymouth_on_boot_progress (script_state_t *state, script_lib_plymouth_data_t *data, double duration, double progress) { script_obj_t *duration_obj = script_obj_new_number (duration); script_obj_t *progress_obj = script_obj_new_number (progress); script_return_t ret = script_execute_object (state, data->script_boot_progress_func, NULL, duration_obj, progress_obj, NULL); script_obj_unref (ret.object); script_obj_unref (duration_obj); script_obj_unref (progress_obj); }
void script_lib_plymouth_on_quit (script_state_t *state, script_lib_plymouth_data_t *data) { script_return_t ret = script_execute_object (state, data->script_quit_func, NULL, NULL); script_obj_unref (ret.object); }
static script_return_t plymouth_set_function (script_state_t *state, void *user_data) { script_obj_t **script_func = user_data; script_obj_t *obj = script_obj_hash_get_element (state->local, "function"); script_obj_deref (&obj); script_obj_unref (*script_func); *script_func = obj; return script_return_obj_null (); }
static bool start_script_animation (ply_boot_splash_plugin_t *plugin) { ply_list_node_t *node; script_obj_t *target_obj; script_obj_t *value_obj; script_env_var_t *env_var; assert (plugin != NULL); plugin->script_state = script_state_new (plugin); for (node = ply_list_get_first_node (plugin->script_env_vars); node != NULL; node = ply_list_get_next_node (plugin->script_env_vars, node)) { env_var = ply_list_node_get_data (node); target_obj = script_obj_hash_get_element (plugin->script_state->global, env_var->key); value_obj = script_obj_new_string (env_var->value); script_obj_assign (target_obj, value_obj); } plugin->script_image_lib = script_lib_image_setup (plugin->script_state, plugin->image_dir); plugin->script_sprite_lib = script_lib_sprite_setup (plugin->script_state, plugin->displays); plugin->script_plymouth_lib = script_lib_plymouth_setup (plugin->script_state, plugin->mode); plugin->script_math_lib = script_lib_math_setup (plugin->script_state); plugin->script_string_lib = script_lib_string_setup (plugin->script_state); ply_trace ("executing script file"); script_return_t ret = script_execute (plugin->script_state, plugin->script_main_op); script_obj_unref (ret.object); if (plugin->keyboard != NULL) ply_keyboard_add_input_handler (plugin->keyboard, (ply_keyboard_input_handler_t) on_keyboard_input, plugin); on_timeout (plugin); return true; }
script_lib_plymouth_data_t *script_lib_plymouth_setup (script_state_t *state, ply_boot_splash_mode_t mode) { script_lib_plymouth_data_t *data = malloc (sizeof(script_lib_plymouth_data_t)); data->script_refresh_func = script_obj_new_null (); data->script_boot_progress_func = script_obj_new_null (); data->script_root_mounted_func = script_obj_new_null (); data->script_keyboard_input_func = script_obj_new_null (); data->script_update_status_func = script_obj_new_null (); data->script_display_normal_func = script_obj_new_null (); data->script_display_password_func = script_obj_new_null (); data->script_display_question_func = script_obj_new_null (); data->script_display_message_func = script_obj_new_null (); data->script_hide_message_func = script_obj_new_null (); data->script_quit_func = script_obj_new_null (); data->mode = mode; script_obj_t *plymouth_hash = script_obj_hash_get_element (state->global, "Plymouth"); script_add_native_function (plymouth_hash, "SetRefreshFunction", plymouth_set_function, &data->script_refresh_func, "function", NULL); script_add_native_function (plymouth_hash, "SetBootProgressFunction", plymouth_set_function, &data->script_boot_progress_func, "function", NULL); script_add_native_function (plymouth_hash, "SetRootMountedFunction", plymouth_set_function, &data->script_root_mounted_func, "function", NULL); script_add_native_function (plymouth_hash, "SetKeyboardInputFunction", plymouth_set_function, &data->script_keyboard_input_func, "function", NULL); script_add_native_function (plymouth_hash, "SetUpdateStatusFunction", plymouth_set_function, &data->script_update_status_func, "function", NULL); script_add_native_function (plymouth_hash, "SetDisplayNormalFunction", plymouth_set_function, &data->script_display_normal_func, "function", NULL); script_add_native_function (plymouth_hash, "SetDisplayPasswordFunction", plymouth_set_function, &data->script_display_password_func, "function", NULL); script_add_native_function (plymouth_hash, "SetDisplayQuestionFunction", plymouth_set_function, &data->script_display_question_func, "function", NULL); script_add_native_function (plymouth_hash, "SetDisplayMessageFunction", plymouth_set_function, &data->script_display_message_func, "function", NULL); script_add_native_function (plymouth_hash, "SetHideMessageFunction", plymouth_set_function, &data->script_hide_message_func, "function", NULL); script_add_native_function (plymouth_hash, "SetQuitFunction", plymouth_set_function, &data->script_quit_func, "function", NULL); script_add_native_function (plymouth_hash, "GetMode", plymouth_get_mode, data, NULL); script_obj_unref (plymouth_hash); data->script_main_op = script_parse_string (script_lib_plymouth_string, "script-lib-plymouth.script"); script_return_t ret = script_execute (state, data->script_main_op); script_obj_unref (ret.object); /* Throw anything sent back away */ return data; }
void script_lib_plymouth_destroy (script_lib_plymouth_data_t *data) { script_parse_op_free (data->script_main_op); script_obj_unref (data->script_refresh_func); script_obj_unref (data->script_boot_progress_func); script_obj_unref (data->script_root_mounted_func); script_obj_unref (data->script_keyboard_input_func); script_obj_unref (data->script_update_status_func); script_obj_unref (data->script_display_normal_func); script_obj_unref (data->script_display_password_func); script_obj_unref (data->script_display_question_func); script_obj_unref (data->script_display_message_func); script_obj_unref (data->script_hide_message_func); script_obj_unref (data->script_quit_func); free (data); }