summaryrefslogtreecommitdiff
path: root/scripting/engine.cpp
blob: 58322f45b43b36607c405ba7970394caf61639f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// engine.cpp

#include "stdafx.h"
#include "engine.h"
#include "../util/file.h"

namespace mongo {
    
    Scope::Scope(){
    }

    Scope::~Scope(){
    }

    ScriptEngine::ScriptEngine(){
    }

    ScriptEngine::~ScriptEngine(){
    }

    int Scope::invoke( const char* code , const BSONObj& args ){
        ScriptingFunction func = createFunction( code );
        uassert( "compile failed" , func );
        return invoke( func , args );
    }

    bool Scope::execFile( const string& filename , bool printResult , bool reportError , bool assertOnError ){
        
        path p( filename );
        if ( is_directory( p ) ){
            cerr << "can't read directory [" << filename << "]" << endl;
            if ( assertOnError )
                assert( 0 );
            return false;
        }
         
        File f;
        f.open( filename.c_str() );
        
        char * data = (char*)malloc( f.len() + 1 );
        data[f.len()] = 0;
        
        f.read( 0 , data , f.len() );
        
        return exec( data , filename , printResult , reportError , assertOnError );
    }



    ScriptEngine * globalScriptEngine;
}