new 4475edb243ed4627f4c5f2c470ca40b3def034d4
[tagua/yd.git] / src / luaapi / luavalue.cpp
blob77f6bb4ad593c09f29f70064e01dee1576b3e694
1 /*
2 Copyright (c) 2006-2008 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #include "luavalue.h"
12 #include <KDebug>
13 #include "imaging.h"
15 namespace LuaApi {
17 void lua_pushvalue(lua_State* l, const LuaValue& value) {
18 if(const double* v = boost::get<double>(&value))
19 lua_pushnumber(l, *v);
20 else if(const QPointF* v = boost::get<QPointF>(&value))
21 Wrapper<QPointF>::create(l, *v);
22 else if(const QRectF* v = boost::get<QRectF>(&value))
23 Wrapper<QRectF>::create(l, *v);
24 else
25 kError() << "Unknown variant type!";
28 void lua_pushvaluemap(lua_State* l, const LuaValueMap* valuemap) {
29 lua_newtable(l); // metatable
31 for(LuaValueMap::const_iterator it = valuemap->begin(); it != valuemap->end(); ++it) {
32 lua_pushvalue(l, it.value());
33 lua_setfield(l, -2, it.key().toAscii().constData());
37 } //end namespace LuaApi