Esempio n. 1
0
void registerFunction(const string& name, RetT(*f)(ArgT0, ArgT1))
{
    TypeSystem* ts = TypeSystem::instance();
    IType *retT = CType2ScriptType<RetT>::get(ts);
    vector<IType*> argT = {CType2ScriptType<ArgT0>::get(ts), CType2ScriptType<ArgT1>::get(ts)};
    IType *ftype = ts->getFunc(retT, argT);
    SymbolTableManager::instance()->global()->addSymbol(name, ftype);
    CodeManager::instance()->registerFunction(name, FunctionPtr(new CFunction2<RetT, ArgT0, ArgT1>(f)));
}
Esempio n. 2
0
void registerVarLengFunction(const string& name, CVarlengFunction::FuncT f)
{
    TypeSystem* ts = TypeSystem::instance();
    IType *retT = CType2ScriptType<int>::get(ts);
    vector<IType*> argT = {CType2ScriptType<const char*>::get(ts)};
    IType *ftype = ts->getFunc(retT, argT);
    dynamic_cast<FunctionType*>(ftype)->isVarLengOfArg = true;
    SymbolTableManager::instance()->global()->addSymbol(name, ftype);
    CodeManager::instance()->registerFunction(name, FunctionPtr(new CVarlengFunction(f)));
}
Esempio n. 3
0
RetT callFromC(IFunction *func, RuntimeEnv* env)
{
    TypeSystem* ts = TypeSystem::instance();
    IType *retT = CType2ScriptType<RetT>::get(ts);
    vector<IType*> argT = {};
    IType *ftype = ts->getFunc(retT, argT);

    int retSize = retT->getSize();
    int retArgSize = retSize;
    env->pushValue(RetT());

    env->pushFrame(retArgSize);
    func->call(env);
    env->popFrame(retSize);

    RetT r;
    env->popValue(r);
    return r;
}