Advertisement
C4Cypher

testluaMR

Aug 26th, 2014
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 1.49 KB | None | 0 0
  1. %-----------------------------------------------------------------------------%
  2. % vim: ft=mercury
  3. %-----------------------------------------------------------------------------%
  4. % Copyright (C) 2014 Charlie H. McGee IV.
  5. % This file may only be copied under the terms of the GNU Library General
  6. % Public License - see the file COPYING.LIB in the Mercury distribution.
  7. %-----------------------------------------------------------------------------%
  8. %
  9. % File: testluaMR.m.
  10. % Main author: c4cypher.
  11. % Stability: low.
  12. %
  13. % Test the luaMR library.
  14. %
  15. %-----------------------------------------------------------------------------%
  16. %-----------------------------------------------------------------------------%
  17.  
  18. :- module testluaMR.
  19.  
  20. :- interface.
  21.  
  22. :- import_module io.
  23.  
  24. :- pred main(io::di, io::uo) is det.
  25.  
  26.  
  27. :- implementation.
  28.  
  29. :- import_module univ.
  30. :- import_module list.
  31. :- import_module exception.
  32.  
  33. :- import_module luaMR.
  34. :- import_module luaMR.api.
  35. :- import_module float.
  36. :- import_module int.
  37.  
  38. :- pragma foreign_import_module("C", luaMR).
  39.  
  40. main(!IO) :-
  41.     L = lua_new,
  42.     impure lua_pushfunc(L, add),
  43.     impure lua_pushinteger(L, 1),
  44.     impure lua_pushinteger(L, 1),
  45.     impure lua_call(L, 2, 1) = _,
  46.     semipure Result = lua_tonumber(L, index(-1)),
  47.     print(Result, !IO).
  48.  
  49. :- pragma promise_pure(main/2).
  50.  
  51. :- impure func add(lua) = int.
  52.  
  53. add(L) = 1 :-
  54.     semipure A = lua_tonumber(L, index(1)),
  55.     semipure B = lua_tonumber(L, index(2)),
  56.     impure lua_pushnumber(L, A + B).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement