stack.cpp 727 B

123456789101112131415161718192021222324252627282930
  1. #include <luwra.hpp>
  2. #include <iostream>
  3. static
  4. double sum3(int a, int b, double c) {
  5. return (a + b) * c;
  6. }
  7. int main() {
  8. luwra::StateWrapper state;
  9. state.loadStandardLibrary();
  10. // Build stack
  11. luwra::push(state, 13);
  12. luwra::push(state, 37);
  13. luwra::push(state, 42.2);
  14. // Each value can be retrieved individually.
  15. std::cout << "a = " << luwra::read<int>(state, 1) << std::endl;
  16. std::cout << "b = " << luwra::read<int>(state, 2) << std::endl;
  17. std::cout << "c = " << luwra::read<double>(state, 3) << std::endl;
  18. // ... which is a little cumbersome. Instead we might apply a fitting function to our stack.
  19. std::cout << "(a + b) * c = "
  20. << luwra::apply(state, sum3)
  21. << std::endl;
  22. return 0;
  23. }