Advertisement
C0BRA

Lua++

Aug 17th, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 KB | None | 0 0
  1. // STL
  2. #include <iostream>
  3.  
  4. // Lua
  5. #include "Lua++.hpp"
  6.  
  7. using namespace std;
  8.  
  9. void PrintTable(Lua::Variable tbl, int depth = 0)
  10. {
  11.     for(auto pair : tbl.pairs())
  12.     {
  13.         for(int i = 0; i < depth; i++)
  14.             cout << '\t';
  15.        
  16.         if(pair.second.GetType() == Lua::Type::Table)
  17.         {
  18.             cout << pair.first.ToString() << ":\n";
  19.             return PrintTable(pair.second, depth + 1);
  20.         }
  21.        
  22.         cout << pair.first.ToString() << " = " << pair.second.ToString() << "\n";
  23.     }
  24. }
  25.  
  26. int main(int argc, char** argv)
  27. {
  28.     cout << "\n";
  29.     try
  30.     {
  31.         Lua::State state;
  32.        
  33.         state.LoadStandardLibary();
  34.         state.DoString("test = {a = 'b', nested = {hi = 'gutten tag', [function() end] = true}, some_int = 1337}", "test");
  35.        
  36.         PrintTable(state["test"]);
  37.     }
  38.     catch(Lua::Exception ex)
  39.     {
  40.         cout << "Lua exception: \n" << ex.what() << "\n";
  41.     }
  42.    
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement