Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- table_value(Table, Key, Value, L) :-
- semipure det_checkstack(L, 6),
- semipure var_type(Table, table_type, L),
- impure lua_newtable(L), % Memo set table
- impure push_var(Table, L),
- impure lua_pushboolean(L, yes),
- impure lua_rawset(L, -3), % Add the Table to the memo set table
- semipure Last = lua_toref(L, -1),
- impure lua_pop(L, 1).
- semipure table_value(Table, Key, Value, Last, L).
- :- semipure pred table_value(var, value, value, ref, lua).
- :- mode valid_table(in, out, out, in, in) is nondet.
- table_value(Table, Key, Value, Last, L) :-
- impure push_var(Table, L) % Table being iterated
- impure lua_pushref(L, Last), % Last key
- impure lua_next(L, -2), % Pop the last key and push the next pair
- % The stack should now look like [Table, Key, Value]
- semipure lua_isnil(L, -2) -> % Is there another pair?
- impure lua_pop(L, 3), % Clear the stack
- fail % There are no more pairs
- ;
- semipure Next = lua_toref(L, -2),
- semipure Key = to_value(-2, L),
- semipure Value = to_value(-1, L),
- impure lua_pop(L, 3), % Clear the stack
- ;
- table_value(Table, Key, Value, Next, L).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement