示例#1
0
static ekU32 fileIterate(struct ekContext *E, ekU32 argCount)
{
    ekValue *thisValue;
    ekValue *ret = ekValueNullPtr;
    ekValue *chompValue = NULL;
    ekFile *file;
    ekValue *closure;

    if(!ekContextGetArgs(E, argCount, "*F|?", &thisValue, &chompValue))
    {
        return ekContextArgsFailure(E, argCount, "file.iterate([optional bool] chompNewline)");
    }

    file = (ekFile *)thisValue->ptrVal;

    if(chompValue)
    {
        chompValue = ekValueToBool(E, chompValue);
    }
    else
    {
        chompValue = ekValueCreateInt(E, 0);
    }

    closure = ekValueCreateCFunction(E, fileIterator);
    closure->closureVars = ekMapCreate(E, EMKT_STRING);
    ekMapGetS2P(E, closure->closureVars, "file") = thisValue;
    ekMapGetS2P(E, closure->closureVars, "chomp") = chompValue;
    ekContextReturn(E, closure);
}
示例#2
0
void ekValueTypeAddIntrinsic(struct ekContext *E, ekValueType *type, const char *name, ekCFunction func)
{
    if(!type->intrinsics)
    {
        type->intrinsics = ekMapCreate(E, EMKT_STRING);
    }
    ekMapGetS2P(E, type->intrinsics, name) = func;
}
示例#3
0
static ekU32 regexGMatch(struct ekContext * E, ekU32 argCount)
{
    ekRegex * regex = regexCreateMatchFromArgs(E, argCount, "re.gmatch([string] subject, [string] pattern, [optional string] options)");
    if (regex) {
        ekValue * closure = ekValueCreateCFunction(E, regexGMatchIterator);
        ekValue * regexValue = ekValueCreate(E, ekValueTypeId(E, 'R'));
        regexValue->ptrVal = regex;
        closure->closureVars = ekMapCreate(E, EMKT_STRING);
        ekMapGetS2P(E, closure->closureVars, "regex") = regexValue;
        ekContextReturn(E, closure);
    }
    ekContextReturn(E, ekValueNullPtr);
}
示例#4
0
static ekU32 fileCreateIterator(struct ekContext *E, ekU32 argCount)
{
    ekValue *thisValue = NULL;
    ekValue *closure;

    if(!ekContextGetArgs(E, argCount, "F", &thisValue))
    {
        return ekContextArgsFailure(E, argCount, "file iterator missing argument");
    }

    closure = ekValueCreateCFunction(E, fileIterator);
    closure->closureVars = ekMapCreate(E, EMKT_STRING);
    ekMapGetS2P(E, closure->closureVars, "file") = thisValue;
    ekMapGetS2P(E, closure->closureVars, "chomp") = ekValueCreateInt(E, 0);
    ekContextReturn(E, closure);
}