Comments (6)
Should be possible by accessing class metatable and using the internal keys luabridge use. Will try to provide some working snippets as soon as i'm back to the laptop.
from luabridge3.
Do you need to access them from lua or c++ ?
from luabridge3.
luabridge::setHideMetatables(false);
luabridge::getGlobalNamespace(L)
.addFunction("getMetatableClass", [](const luabridge::LuaRef& ref) -> luabridge::LuaRef
{
if (!ref.isTable())
return luabridge::LuaRef(ref.state());
ref.push();
luabridge::lua_rawgetp(ref.state(), -1, luabridge::detail::getClassKey());
auto mt = luabridge::LuaRef::fromStack(ref.state(), 1);
for (const auto& p : luabridge::pairs(mt))
std::cout << p.first << " " << p.second << std::endl;
return mt;
})
.beginClass<ExampleStringifiableClass>("ExampleStringifiableClass")
.addConstructor<void(*) ()>()
.addFunction("nonConstMethod", [](ExampleStringifiableClass*) {})
.addFunction("constMethod", [](const ExampleStringifiableClass*) {})
.endClass();
runLua(R"(
local t = ExampleStringifiableClass()
local mt = getmetatable(t)
getMetatableClass(mt)
)");
this will print:
userdata: 0xc07 table: 0x6000017084c0
"__gc" function: 0x600000c09aa0
"nonConstMethod" function: 0x600001708780
userdata: 0x71 "ExampleStringifiableClass"
userdata: 0x5e7 table: 0x600001708600
userdata: 0x6e7 table: 0x6000017085c0
"__newindex" function: 0x600000c09ad0
"__index" function: 0x600000c09b00
"constMethod" function: 0x600001708800
Will provide some facilities to extract this kind of information in a more straight forward way
from luabridge3.
I need to access them from Lua. It is a powerful tool for verifying the correctness of the LuaBridge implementation, as well as presenting the class framework to users as a learning aid.
from luabridge3.
We can design a specific help table for that. So registering a method could push an entry in the table with the description of the method and argument type as seen from c++ (but not name) registered in the class
from luabridge3.
Pre-2019, instead of hard-coded usersdata values the tables above had string keys, _class
, _propget
, _propset
, and _static
. (They may have been a _const
key too, but if so I never used it.) I only need to be able to iterate them and get their names. I don't need to modify or call the values.
I am currently doing exactly what you suggested and adding helper tables as I register the classes. I use refl-cpp
to reflect the C++ classes at compile time so that all of my registrations use the same code. The challenge with refl-cpp
is that lack of useful support for overloaded methods. The current support would require me to know and hardcode the function signatures in the central routine where I'm processing them rather than in the lists where I list them, so right now I can't use refl-cpp
for everything.
from luabridge3.
Related Issues (20)
- std::map<std::string, std::string> in lua HOT 3
- Namespace registration fails on assert when split across separate calls HOT 1
- C++ functions that take null pointer arguments HOT 2
- Lua error crashes host with CFunction but not typed function. HOT 22
- Recent LB3 Change Causes my code not to compile. HOT 2
- Linker error when building project submodules: /usr/bin/ld: cannot find -lreadline HOT 2
- Compiler error use of deleted function luabridge::TypeResult<T>::TypeResult(...) HOT 6
- Enhancement Request: Custom error function for `lua_pcall`. HOT 11
- Error C3861 (using with Luau) HOT 3
- Can I cast types inside Lua? HOT 4
- Duplicate symbols on Win32 with default __stdcall HOT 9
- Debug names of C functions for Luau HOT 8
- Extensible class bug with inheritance
- Add support for addStaticIndexMetamethod and addStaticNewIndexMetamethod
- Using LuaBridge3 in a precompiled header on MSVC leads to an internal compiler error HOT 2
- Use of std::shared_ptr on classes without `std::enable_shared_from_this` HOT 1
- Stateful lambdas registered as functions loose state HOT 2
- Compile error with Cfunc property getter/setter HOT 2
- std::vector to 0-based Lua table HOT 5
- MSC Warning C4146 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from luabridge3.