Advertisement
C4Cypher

Finally

Aug 22nd, 2014
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.51 KB | None | 0 0
  1. mr_call(L) = R :-
  2.     [E, _] = solutions(try(mr_call(L))),
  3.     require_complete_switch [E]
  4.     ( E = succeeded(R)
  5.     ; E = failed,
  6.         impure lua_pushboolean(L, no),
  7.         R = 1
  8.     ; E = exception(U),
  9.         impure lua_pushnil(L),
  10.         impure lua_pushuniv(L, U),
  11.         R = 2
  12.     ).
  13.        
  14.  
  15. :- pred mr_call(lua::in, int::out) is cc_multi.
  16.    
  17. mr_call(L,  R) :-
  18.     semipure lua_getupvalue(L, 1),
  19.     semipure univ(F) = lua_touserdata(L, -1) ->
  20.         R = F(L)   
  21.     ;
  22.         impure lua_error(L,
  23.         "Called Mercury function without valid func upvalue.").
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement