Example #1
0
static void addPermanentFile(struct ekContext *E, ekValue *module, const char *name, FILE *f, int permanentState)
{
    ekValue *fileValue = ekValueCreate(E, ekValueTypeId(E, 'F'));
    ekFile *file = (ekFile *)ekAlloc(sizeof(ekFile));
    file->filename = ekValueCreateString(E, name);
    file->state = permanentState;
    file->permanent = ekTrue;
    file->handle = f;
    fileValue->ptrVal = file;

    ekValueObjectSetMember(E, module, name, fileValue);
}
Example #2
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);
}
Example #3
0
static ekU32 newFile(struct ekContext *E, ekU32 argCount)
{
    ekValue *ret = ekValueNullPtr;
    ekValue *filenameValue = NULL;
    ekFile *file;

    if(!ekContextGetArgs(E, argCount, "s", &filenameValue))
    {
        return ekContextArgsFailure(E, argCount, "file([string] filename)");
    }

    ret = ekValueCreate(E, ekValueTypeId(E, 'F'));
    file = (ekFile *)ekAlloc(sizeof(ekFile));
    file->filename = absolutePath(E, filenameValue); // takes ownership
    ret->ptrVal = file;

    ekContextReturn(E, ret);
}
Example #4
0
static ekU32 fileOpen(struct ekContext *E, ekU32 argCount)
{
    ekValue *fileValue = ekValueNullPtr;
    ekValue *filenameValue;
    ekValue *modesValue = NULL;
    ekFile *file;

    if(!ekContextGetArgs(E, argCount, "s|s", &filenameValue, &modesValue)) // assumes "r" if absent
    {
        return ekContextArgsFailure(E, argCount, "file.open([string] filename, [string] modes)");
    }

    fileValue = ekValueCreate(E, ekValueTypeId(E, 'F'));
    file = (ekFile *)ekAlloc(sizeof(ekFile));
    file->filename = absolutePath(E, filenameValue); // takes ownership
    fileValue->ptrVal = file;

    return fileOpenInternal(E, fileValue, modesValue);
}