Initial commit, includes Lua with broken Luabind as a backup for branching purposes
[terrastrategy.git] / src / core / script_core.cpp
blob8ed7855e22285ebe51def9f94e9ca0368db5d659
1 //
2 // Copyright (C) 2008 by Martin Moracek
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 /**
20 * @file script_core.cpp
22 * blahblah
25 #include "lua/lua.h"
27 #include "luabind/luabind.hpp"
28 #include "luabind/operator.hpp"
29 #include "luabind/return_reference_to_policy.hpp"
31 #include "exception.h"
33 #include "core/application.h"
34 #include "core/timer.h"
35 #include "vfs/interface.h"
36 #include "vfs/logfile.h"
38 #include "core/script_core.h"
40 namespace tre {
42 void CoreInitializer::operator () (lua_State * L) const
44 using namespace luabind;
46 // register GameClient class
47 module(L)
49 class_<Timer>("Timer")
50 .def("ScheduleAction", &Timer::ScheduleAction)
51 .def("RemoveAction", &Timer::RemoveAction)
52 .def("GetSystemTime", &Timer::GetSystemTime),
54 class_<Application>("Application")
55 .def("Quit", &Application::Quit)
56 .def_readonly("timer", &Application::timer),
58 // math classes
59 class_<Vector2<float> >("vec2")
60 .def(constructor<float, float>())
61 .def(self + other<Vector2<float> >())
62 .def(self - other<Vector2<float> >())
63 .def(self * float())
64 .def(self / float())
65 .def(self == other<Vector2<float> >())
66 .def("add", &Vector2<float>::operator+=, return_reference_to(_1))
67 .def("sub", &Vector2<float>::operator-=, return_reference_to(_1))
68 .def("mul", &Vector2<float>::operator*=, return_reference_to(_1))
69 .def("div", &Vector2<float>::operator/=, return_reference_to(_1))
70 .def("len", &Vector2<float>::Length)
71 .def("normalize", &Vector2<float>::Normalize)
72 .def_readwrite("x", &Vector2<float>::x)
73 .def_readwrite("y", &Vector2<float>::y),
75 class_<Vector3<float> >("vec3")
76 .def(constructor<float, float, float>())
77 .def(self + other<Vector3<float> >())
78 .def(self - other<Vector3<float> >())
79 .def(self * float())
80 .def(self / float())
81 .def(self == other<Vector3<float> >())
82 .def("add", &Vector3<float>::operator+=, return_reference_to(_1))
83 .def("sub", &Vector3<float>::operator-=, return_reference_to(_1))
84 .def("mul", &Vector3<float>::operator*=, return_reference_to(_1))
85 .def("div", &Vector3<float>::operator/=, return_reference_to(_1))
86 .def("len", &Vector3<float>::Length)
87 .def("normalize", &Vector3<float>::Normalize)
88 .def_readwrite("x", &Vector3<float>::x)
89 .def_readwrite("y", &Vector3<float>::y)
90 .def_readwrite("z", &Vector3<float>::z)