7 #ifndef __lua_LuaComponent_h__ 8 #define __lua_LuaComponent_h__ 15 typedef LuaObject<sp<Component>, LuaContext::e_component> t_lua_component;
23 : t_lua_component(pContext, data) {}
25 static int index(lua_State *pLuaState);
26 static int newindex(lua_State *pLuaState);
27 static int call(lua_State *pLuaState);
28 static int name(lua_State *pLuaState);
29 static int setName(lua_State *pLuaState);
30 static int adjoin(lua_State *pLuaState);
32 void setMethod(
const String &name, lua_CFunction f)
36 bool pushMethod(
String &name)
38 std::map<String, lua_CFunction>::iterator i_methods =
40 if(i_methods == m_methods.end()) {
return false; }
41 lua_State *pLuaState = context()->state();
42 lua_pushstring(pLuaState, name.
c_str());
43 lua_pushcclosure(context()->state(), i_methods->second, 1);
50 return data().is<T>();
52 static void pushComponent(lua_State *pLuaState,
sp<Component> spC)
54 lua_getglobal(pLuaState,
"fe_context");
55 LuaContext *pContext = (LuaContext *)(lua_touserdata(pLuaState,-1));
56 lua_pop(pLuaState, 1);
58 void *pBlock = lua_newuserdata(pLuaState,
67 std::map<String, lua_CFunction> m_methods;
71 class LuaComponentType :
public t_lua_component_t
74 LuaComponentType(LuaContext *pContext,
const String &mtn);
75 virtual ~LuaComponentType(
void){}
76 virtual void pushNewMetaTable(
void);
80 T *to(lua_State *pLuaState,
int index,
int tid)
82 void *pV = lua_touserdata(pLuaState, index);
86 s.
sPrintf(
"type mismatch on arg %d : did you use '.' instead of ':' for method?", index);
87 LuaContext::error(pLuaState, s.
c_str());
91 LuaBaseObject *pB = (LuaBaseObject *)pV;
92 if(pB->type() != pB->context()->lookup(tid))
95 s.
sPrintf(
"type mismatch on argument %d", index);
97 LuaContext::error(pLuaState, s.
c_str());
100 return static_cast<T *
>(pB);
103 template<
class Obj,
class T>
104 sp<T> counted(lua_State *pLuaState,
int index,
int tid)
106 return to<Obj>(pLuaState,index,tid)->
data();
110 sp<T> component(lua_State *pLuaState,
int index)
113 to<LuaComponentObject>(pLuaState, index, LuaContext::e_component);
115 sp<T> spT(pC->data());
120 s.
sPrintf(
"component type mismatch on argument %d", index);
121 LuaContext::error(pLuaState, s.
c_str());
130 sp<T> spT = component<T>(pLuaState, index);
132 LuaContext::e_component);
137 Record record(lua_State *pLuaState,
int index);
const FESTRING_I8 * c_str(void) const
Return the contents of the 8-bit buffer cast as signed bytes.
Definition: String.h:352
kernel
Definition: namespace.dox:3
void populateMethods(void)
This is where you directly bind interfaces to lua.
Definition: LuaComponent.cc:793
String & sPrintf(const char *fmt,...)
Populate the string in the manner of sprintf().
Definition: String.cc:529
Automatically reference-counted string container.
Definition: String.h:128
Reference to an instance of a Layout.
Definition: RecordSB.h:35
Component to Lua binding object.
Definition: LuaComponent.h:18
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53