Made it work on VC6.5 again. This involves changing generate_converter
[luabind.git] / test / main.cpp
blob8a4766980cfc6c152babf8d8aeaf59b6cd85f77d
1 // Copyright (c) 2005 Daniel Wallin, Arvid Norberg
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the "Software"),
5 // to deal in the Software without restriction, including without limitation
6 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 // and/or sell copies of the Software, and to permit persons to whom the
8 // Software is furnished to do so, subject to the following conditions:
10 // The above copyright notice and this permission notice shall be included
11 // in all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
14 // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
15 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
18 // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21 // OR OTHER DEALINGS IN THE SOFTWARE.
23 #include <iostream>
25 extern "C"
27 #include "lauxlib.h"
28 #include "lualib.h"
31 #include <luabind/open.hpp>
32 #include "test.hpp"
34 extern "C" struct lua_State;
36 void test_main(lua_State*);
38 struct lua_state
40 lua_state();
41 ~lua_state();
43 operator lua_State*() const;
44 void check() const;
46 private:
47 lua_State* m_state;
48 int m_top;
51 lua_state::lua_state()
52 : m_state(lua_open())
54 luaopen_base(m_state);
55 lua_baselibopen(m_state);
56 m_top = lua_gettop(m_state);
57 luabind::open(m_state);
60 lua_state::~lua_state()
62 TEST_CHECK(lua_gettop(m_state) == m_top);
63 lua_close(m_state);
66 void lua_state::check() const
68 TEST_CHECK(lua_gettop(m_state) == m_top);
71 lua_state::operator lua_State*() const
73 return m_state;
76 int pcall_handler(lua_State* L)
78 return 1;
81 void dostring(lua_State* state, char const* str)
83 lua_pushcclosure(state, &pcall_handler, 0);
85 if (luaL_loadbuffer(state, str, std::strlen(str), str))
87 std::string err(lua_tostring(state, -1));
88 lua_pop(state, 2);
89 throw err;
92 if (lua_pcall(state, 0, 0, -2))
94 std::string err(lua_tostring(state, -1));
95 lua_pop(state, 2);
96 throw err;
99 lua_pop(state, 1);
102 bool tests_failure = false;
104 void report_failure(char const* err, char const* file, int line)
106 std::cerr << file << ":" << line << "\"" << err << "\"\n";
107 tests_failure = true;
110 int main()
114 lua_state L;
115 test_main(L);
116 return tests_failure ? 1 : 0;
118 catch (std::exception const& e)
120 std::cerr << "Terminated with exception: \"" << e.what() << "\"\n";
121 return 1;
123 catch (...)
125 std::cerr << "Terminated with unknown exception\n";
126 return 1;