2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
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 if(lua_isnil(l
, -1)) {
24 QDir
* dir
= reinterpret_cast<QDir
*>(lua_touserdata(l
, -1));
26 return QDir::cleanPath(QDir::isAbsolutePath(f
) ? f
: dir
->filePath(f
));
29 Loader::Context
* GenericWrapperBase::retrieve_context(lua_State
* l
) {
32 lua_getfield(l
, LUA_REGISTRYINDEX
, LOADING_CONTEXT
);
33 Loader::Context
* retv
= reinterpret_cast<Loader::Context
*>(lua_touserdata(l
, -1));
38 void GenericWrapperBase::set_property(lua_State
* l
, const char* name
, lua_CFunction get
,
39 lua_CFunction set
, int index
) {
42 lua_getfield(l
,index
,".get");
43 lua_pushcfunction(l
, get
);
44 lua_setfield(l
, -2, name
);
48 lua_getfield(l
,index
,".set");
49 lua_pushcfunction(l
, set
);
50 lua_setfield(l
, -2, name
);
55 void GenericWrapperBase::set_method(lua_State
* l
, lua_CFunction f
, const char* name
,
59 lua_getfield(l
,index
,".methods");
60 lua_pushcfunction(l
, f
);
61 lua_setfield(l
, -2, name
);
65 void GenericWrapperBase::set_meta_method(lua_State
* l
, lua_CFunction f
,
66 const char* name
, int index
) {
69 lua_pushcfunction(l
, f
);
70 lua_setfield(l
, index
-1, name
);
73 int GenericWrapperBase::object_meta_index_event(lua_State
* l
) {
75 /* should i check the object before the meta table? no... */
76 lua_getmetatable(l
,-2);
79 lua_pushstring(l
,".methods");
84 //key, MT, .methods, method
85 if(!lua_isnil(l
,-1)) {
94 lua_pushstring(l
,".get");
99 //key, MT, .get, getter
100 if(!lua_isnil(l
,-1)) {
109 luaL_error(l
, "Can't get unexisting method/property %s\n", lua_tostring(l
,-4));
114 int GenericWrapperBase::object_meta_newindex_event(lua_State
* l
) {
115 StackCheck
check(l
, -2);
117 /* should i check the object before the meta table? no... */
118 lua_getmetatable(l
,-3);
121 lua_pushstring(l
,".set");
126 //key, value, MT, .set, setter
127 if(!lua_isnil(l
,-1)) {
138 luaL_error(l
, "Can't set unexisting property %s\n", lua_tostring(l
,-5));
144 } //end namespace LuaApi