2 Copyright (c) 2006 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.
12 #include "genericwrapper.h"
16 QString
GenericWrapperBase::file_path(lua_State
* l
, const QString
& f
) {
19 lua_getfield(l
, LUA_REGISTRYINDEX
, CURRENT_DIRECTORY
);
20 QDir
* dir
= reinterpret_cast<QDir
*>(lua_touserdata(l
, -1));
22 return QDir::cleanPath(QDir::isAbsolutePath(f
) ? f
: dir
->filePath(f
));
25 Loader::Context
* GenericWrapperBase::retrieve_context(lua_State
* l
) {
28 lua_getfield(l
, LUA_REGISTRYINDEX
, LOADING_CONTEXT
);
29 Loader::Context
* retv
= reinterpret_cast<Loader::Context
*>(lua_touserdata(l
, -1));
34 void GenericWrapperBase::set_property(lua_State
* l
, const char* name
, lua_CFunction get
,
35 lua_CFunction set
, int index
) {
38 lua_getfield(l
,index
,".get");
39 lua_pushcfunction(l
, get
);
40 lua_setfield(l
, -2, name
);
44 lua_getfield(l
,index
,".set");
45 lua_pushcfunction(l
, set
);
46 lua_setfield(l
, -2, name
);
51 void GenericWrapperBase::set_method(lua_State
* l
, lua_CFunction f
, const char* name
,
55 lua_getfield(l
,index
,".methods");
56 lua_pushcfunction(l
, f
);
57 lua_setfield(l
, -2, name
);
61 void GenericWrapperBase::set_meta_method(lua_State
* l
, lua_CFunction f
,
62 const char* name
, int index
) {
65 lua_pushcfunction(l
, f
);
66 lua_setfield(l
, index
-1, name
);
69 int GenericWrapperBase::object_meta_index_event(lua_State
* l
) {
71 /* should i check the object before the meta table? no... */
72 lua_getmetatable(l
,-2);
75 lua_pushstring(l
,".methods");
80 //key, MT, .methods, method
81 if(!lua_isnil(l
,-1)) {
90 lua_pushstring(l
,".get");
95 //key, MT, .get, getter
96 if(!lua_isnil(l
,-1)) {
105 luaL_error(l
, "Can't get unexisting method/property %s\n", lua_tostring(l
,-4));
110 int GenericWrapperBase::object_meta_newindex_event(lua_State
* l
) {
111 StackCheck
check(l
, -2);
113 /* should i check the object before the meta table? no... */
114 lua_getmetatable(l
,-3);
117 lua_pushstring(l
,".set");
122 //key, value, MT, .set, setter
123 if(!lua_isnil(l
,-1)) {
134 luaL_error(l
, "Can't set unexisting property %s\n", lua_tostring(l
,-5));
140 } //end namespace LuaApi