Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
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;
}