You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! I did that myself in a lazy way.
for example if you have:
class A
{
public:
string str;
string getStr() { return str; }
void setStr(const string& str) { this->str = str; }
};
SLB::Class<A>("Namespace::A")
.constructor()
.set("getStr", &A::getStr)
.set("setStr", &A::setStr)
.property("str", &A::str)
;
then you can use it from lua these ways:
a = A()
a:setStr('123')
print(a:getStr())
a.str = '321'
print(a.str)
with my changes to SLB.cpp you should globally define SLB_OBJECT_PROPERTY so
that it could be seen from SLB.cpp
and then you can use the following:
a.Str = '456'
print(a.Str)
that is if SLB does not find a property named Str then in searches for
corresponding functions getStr and setStr
here are my changes to SLB.cpp (changeset: 288:e440976b9f9f)
diff --git a/source/SLB/SLB.cpp b/source/SLB/SLB.cpp
index 5394ab4..63d4a8f 100644
--- a/source/SLB/SLB.cpp
+++ b/source/SLB/SLB.cpp
@@ -342,6 +342,21 @@ namespace SLB {
prop->get(L,1);
return 1;
}
+#ifdef SLB_OBJECT_PROPERTY
+ {
+ auto fkey = String("get") + key;
+ if(getElementsMap().count(fkey))
+ {
+ auto func = static_cast<const
FuncCall*>(getElementsMap().at(fkey).get());
+ if(func)
+ {
+ lua_pop(L, 1);
+ const_cast<FuncCall*>(func)->call(L);
+ return 1;
+ }
+ }
+ }
+#endif
}
}
if (result < 1)
@@ -379,6 +394,21 @@ namespace SLB {
prop->set(L,1);
return 1;
}
+#ifdef SLB_OBJECT_PROPERTY
+ {
+ auto fkey = String("set") + key;
+ if(getElementsMap().count(fkey))
+ {
+ auto func = static_cast<const FuncCall*>(getElementsMap().at(fkey).get());
+ if(func)
+ {
+ lua_replace(L, 2);
+ const_cast<FuncCall*>(func)->call(L);
+ return 1;
+ }
+ }
+ }
+#endif
}
if (_meta__newindex[type].valid())
{
Original issue reported on code.google.com by
[email protected]
on 1 Apr 2013 at 10:41The text was updated successfully, but these errors were encountered: