src/melon/modules/json/json_module.c
static TByte parseFileFunc(VM* vm)
{
    melM_arg(vm, jsonFile, MELON_TYPE_STRING, 0);

    Value* openFileFunc = melGetClosureFromModule(vm, &ioKey, &openFileKey);
    assert(openFileFunc != NULL);

    melM_stackPush(&vm->stack, openFileFunc);
    melM_stackPush(&vm->stack, jsonFile);

    melCallClosureSyncVM(vm, 1, 0, 1);

    Value fileResult = *melM_stackOffset(&vm->stack, 0);

    if (fileResult.type != MELON_TYPE_OBJECT)
    {
        melM_stackPop(&vm->stack);
        melM_vstackPushNull(&vm->stack);
        return 1;
    }
    
    melSaveAndPauseGC(vm, &vm->gc);
    melM_stackPop(&vm->stack);

    Value* readFileFunc = melGetClosureFromModule(vm, &ioKey, &readFileKey);
    assert(readFileFunc != NULL);

    melM_stackPush(&vm->stack, readFileFunc);
    melM_stackPush(&vm->stack, &fileResult);
    melRestorePauseGC(vm, &vm->gc);

    melCallClosureSyncVM(vm, 1, 0, 1);

    Value contentResult = *melM_stackOffset(&vm->stack, 0);

    if (contentResult.type != MELON_TYPE_STRING)
    {
        melM_stackPop(&vm->stack);
        melM_vstackPushNull(&vm->stack);
        return 1;
    }

    return parseString(vm, &contentResult);
}
/***
 * Reads and parses the provided JSON file.
 * 
 * @arg jsonPath A valid path to a readable file
 * 
 * @returns The deserialized JSON or `null` if parsing failed.
 */
Reads and parses the provided JSON file.

@arg jsonPath A valid path to a readable file

@returns The deserialized JSON or `null` if parsing failed.
Reads and parses the provided JSON file . @arg jsonPath A valid path to a readable file @returns The deserialized JSON or ` null ` if parsing failed .
static TByte parseFileFunc(VM* vm)
{
    melM_arg(vm, jsonFile, MELON_TYPE_STRING, 0);
    Value* openFileFunc = melGetClosureFromModule(vm, &ioKey, &openFileKey);
    assert(openFileFunc != NULL);
    melM_stackPush(&vm->stack, openFileFunc);
    melM_stackPush(&vm->stack, jsonFile);
    melCallClosureSyncVM(vm, 1, 0, 1);
    Value fileResult = *melM_stackOffset(&vm->stack, 0);
    if (fileResult.type != MELON_TYPE_OBJECT)
    {
        melM_stackPop(&vm->stack);
        melM_vstackPushNull(&vm->stack);
        return 1;
    }
    melSaveAndPauseGC(vm, &vm->gc);
    melM_stackPop(&vm->stack);
    Value* readFileFunc = melGetClosureFromModule(vm, &ioKey, &readFileKey);
    assert(readFileFunc != NULL);
    melM_stackPush(&vm->stack, readFileFunc);
    melM_stackPush(&vm->stack, &fileResult);
    melRestorePauseGC(vm, &vm->gc);
    melCallClosureSyncVM(vm, 1, 0, 1);
    Value contentResult = *melM_stackOffset(&vm->stack, 0);
    if (contentResult.type != MELON_TYPE_STRING)
    {
        melM_stackPop(&vm->stack);
        melM_vstackPushNull(&vm->stack);
        return 1;
    }
    return parseString(vm, &contentResult);
}
static TByte parseFileFunc ( VM * vm ) { melM_arg ( vm , jsonFile , MELON_TYPE_STRING , 0 ) ; Value * openFileFunc = melGetClosureFromModule ( vm , & ioKey , & openFileKey ) ; assert ( openFileFunc != NULL ) ; melM_stackPush ( & vm -> stack , openFileFunc ) ; melM_stackPush ( & vm -> stack , jsonFile ) ; melCallClosureSyncVM ( vm , 1 , 0 , 1 ) ; Value fileResult = * melM_stackOffset ( & vm -> stack , 0 ) ; if ( fileResult . type != MELON_TYPE_OBJECT ) { melM_stackPop ( & vm -> stack ) ; melM_vstackPushNull ( & vm -> stack ) ; return 1 ; } melSaveAndPauseGC ( vm , & vm -> gc ) ; melM_stackPop ( & vm -> stack ) ; Value * readFileFunc = melGetClosureFromModule ( vm , & ioKey , & readFileKey ) ; assert ( readFileFunc != NULL ) ; melM_stackPush ( & vm -> stack , readFileFunc ) ; melM_stackPush ( & vm -> stack , & fileResult ) ; melRestorePauseGC ( vm , & vm -> gc ) ; melCallClosureSyncVM ( vm , 1 , 0 , 1 ) ; Value contentResult = * melM_stackOffset ( & vm -> stack , 0 ) ; if ( contentResult . type != MELON_TYPE_STRING ) { melM_stackPop ( & vm -> stack ) ; melM_vstackPushNull ( & vm -> stack ) ; return 1 ; } return parseString ( vm , & contentResult ) ; }
Reads and parses the provided JSON file.
Reads and parses the provided JSON file .