/*
    Copyright (c) 2007 SIEGE Development Team
    All rights reserved.
    
    This file is part of libSIEGE.
    
    This software is copyrighted work licensed under the terms of the
    2-clause BSD license. Please consult the file "license.txt" for
    details.
    
    If you did not recieve the file with this program, please email
    Tim Chas <darkuranium@gmail.com>.
*/

#include <siege/siege.h>

#include <stdlib.h>
#include <stdio.h>

#include <squirrel.h>
#include <sqstdio.h>
#include <sqstdaux.h>

void callFoo(HSQUIRRELVM v, int n, float f, char* s)
{
    int top = sq_gettop(v);
    sq_pushroottable(v);
    sq_pushstring(v, _SC("foo"), -1);
    if(SQ_SUCCEEDED(sq_get(v,-2)))
    {
            sq_pushroottable(v);
            sq_pushinteger(v, n);
            sq_pushfloat(v, f);
            sq_pushstring(v, s, -1);
            sq_call(v, 4, 0, 1);
    }
    sq_settop(v, top);
}

void sgsPrint(HSQUIRRELVM v, const SQChar *format, ...)
{
        va_list args;
        va_start(args, format);
        vprintf(format, args);
        va_end(args);
}
void sgsPrintError(HSQUIRRELVM v, const SQChar *format, ...)
{
        va_list args;
        va_start(args, format);
        vfprintf(stderr, format, args);
        va_end(args);
}

int main()
{
    HSQUIRRELVM v = sq_open(1024);
    sqstd_seterrorhandlers(v);
    sq_setprintfunc(v, sgsPrint, sgsPrintError);

    sq_pushroottable(v);

    if(SQ_SUCCEEDED(sqstd_dofile(v, _SC("main.nut"), 0, 1)))
        callFoo(v, 15, 0.75, "hi there!");

    sq_pop(v, 1);
    sq_close(v);

    return 0;
}
