Exemplo n.º 1
0
//-------------------------------------------------------------------
// PURPOSE: Load script to memory ( and free malloc previous if exists)
// PARAMETERS:  fn - full path of script
//
// RESULTS: conf.script_file
//
// NOTES:  1. Try to load fn, if fn or file is empty - SCRIPT_DEFAULT_FILENAME, 
//                if default not exists - display 'NO SCRIPT'
//         2. Update conf.script_file, title, submenu
//-------------------------------------------------------------------
void script_load(const char *fn)
{
    char* buf;

    // if filename is empty, try to load default named script.
    // if no such one, no script will be used
    if ((fn == 0) || (fn[0] == 0))
        fn = SCRIPT_DEFAULT_FILENAME;

    strcpy(conf.script_file, fn);

    get_last_paramset_num();    // update data paths
    script_scan();              // re-fill @title/@names/@range/@value + reset values to @default
    load_params_values();

    gui_update_script_submenu();
}
Exemplo n.º 2
0
//-------------------------------------------------------------------
// PURPOSE: Load script to memory ( and free malloc previous if exists)
// PARAMETERS:  fn - full path of script
//
// RESULTS: conf.script_file
//          script_source_str - loaded script file content
//
// NOTES:  1. Try to load fn, if fn or file is empty - SCRIPT_DEFAULT_FILENAME, 
//                if default not exists - use builtin
//         2. Update conf.script_file, title, submenu
//-------------------------------------------------------------------
void script_load(const char *fn)
{
    int size;
    char* buf;

    if(script_source_str && script_source_str != lua_script_default)
        free((void *)script_source_str);

    // if filename is empty, try to load default named script.
    // if no such one, lua_script_default will be used
    if ( !fn[0] )
    {
        buf = load_file_to_cached( SCRIPT_DEFAULT_FILENAME, &size );
        if ( buf )
                fn = SCRIPT_DEFAULT_FILENAME;
    }
    else
    {
        buf = load_file_to_cached( fn, &size );
    }

    if ( !buf )
    {
        // if failed to load - say "internal" and raise flag need update
        script_source_str = lua_script_default;
        conf.script_file[0] = 0;
    }
    else
    {
        // if ok - set pointers to script
        script_source_str = buf;
        strcpy(conf.script_file, fn);
    }

    get_last_paramset_num( conf.script_file );            // update data paths
    script_scan( conf.script_file );                      // re-fill @title/@names/@order/@range/@value + reset values to @default
    load_params_values( conf.script_file, conf.script_param_set );

    gui_update_script_submenu();
}