Skip to content

Commit 89bddda

Browse files
committed
FEAT: added RL_Get_Value_Resolved as a library function which works like original RL_Get_Value, but with difference, that when resulting value is WORD, GET-WORD, PATH or GET-PATH, result is not this value, or its resolved value.
This is useful when writing dialects as an native extension's code.
1 parent 90a710c commit 89bddda

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/core/a-lib.c

+32
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,38 @@ RL_API u32 RL_Set_Char(REBSER *series, u32 index, u32 chr)
867867
return index;
868868
}
869869

870+
RL_API int RL_Get_Value_Resolved(REBSER *series, u32 index, RXIARG *result)
871+
/*
872+
** Get a value from a block. If value is WORD or PATH, than its value is resolved.
873+
**
874+
** Returns:
875+
** Datatype of value or zero if index is past tail.
876+
** Arguments:
877+
** series - block series pointer
878+
** index - index of the value in the block (zero based)
879+
** result - set to the value of the field
880+
*/
881+
{
882+
REBVAL *value;
883+
if (index >= series->tail) return 0;
884+
value = BLK_SKIP(series, index);
885+
switch (VAL_TYPE(value)) {
886+
case REB_WORD:
887+
case REB_GET_WORD:
888+
889+
value = Get_Var(value);
890+
//printf("resolved type: %u\n", VAL_TYPE(value));
891+
break;
892+
case REB_PATH:
893+
case REB_GET_PATH:
894+
Do_Path(&value, NULL);
895+
value = DS_TOP; // only safe for short time!
896+
break;
897+
}
898+
*result = Value_To_RXI(value);
899+
return Reb_To_RXT[VAL_TYPE(value)];
900+
}
901+
870902
RL_API int RL_Get_Value(REBSER *series, u32 index, RXIARG *result)
871903
/*
872904
** Get a value from a block.

0 commit comments

Comments
 (0)