/*
 * SurgeScript
 * A scripting language for games
 * Copyright 2016-2024 Alexandre Martins <alemartf(at)gmail(dot)com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * runtime/sslib/temp.c
 * SurgeScript standard library: Temporary Storage Area (holds arrays, dicts, etc.)
 */

#include <time.h>
#include "../vm.h"
#include "../object.h"

/* private stuff */
static surgescript_var_t* fun_main(surgescript_object_t* object, const surgescript_var_t** param, int num_params);
static surgescript_var_t* fun_destroy(surgescript_object_t* object, const surgescript_var_t** param, int num_params);

/*
 * surgescript_sslib_register_temp()
 * Register methods
 */
void surgescript_sslib_register_temp(surgescript_vm_t* vm)
{
    surgescript_vm_bind(vm, "__Temp", "state:main", fun_main, 0);
    surgescript_vm_bind(vm, "__Temp", "destroy", fun_destroy, 0);
}



/* my functions */

/* main state */
surgescript_var_t* fun_main(surgescript_object_t* object, const surgescript_var_t** param, int num_params)
{
    /* we reduce the time of tree traversal by deactivating __Temp. As a consequence,
       descendants of __Temp (e.g., Arrays & Dictionaries spawned as its children)
       won't be updated / traversed. __Temp may hold hundreds or thousands of objects,
       and so the benefit of this optimization outweights its cost (as I see it at the
       time of this writing). */
    surgescript_object_set_active(object, false);
    return NULL;
}

/* destroy */
surgescript_var_t* fun_destroy(surgescript_object_t* object, const surgescript_var_t** param, int num_params)
{
    return NULL;
}
