Rev | Line | |
---|
[11519] | 1 | #ifndef LUATB_H |
---|
| 2 | #define LUATB_H |
---|
| 3 | |
---|
| 4 | #include <string> |
---|
| 5 | |
---|
| 6 | struct lua_State; |
---|
| 7 | |
---|
[11673] | 8 | /** |
---|
| 9 | * @brief Makes certain functions visible to lua while staying type-safe |
---|
| 10 | * on the C++ side. |
---|
| 11 | */ |
---|
[11519] | 12 | template<typename ThisType, typename FunctionType> |
---|
| 13 | class LuaTB |
---|
| 14 | { |
---|
| 15 | public: |
---|
[11673] | 16 | /** |
---|
| 17 | * @brief Make a function visible to lua |
---|
| 18 | * @param _this Pointer to the object that owns the function |
---|
| 19 | * @param lua Pointer to the lua state |
---|
| 20 | * @param name Name that will be visible to lua for this function |
---|
| 21 | * |
---|
| 22 | * Only class functions are supported, because that's all we need at |
---|
| 23 | * the moment. Extending it to support normal functions as well should |
---|
| 24 | * be fairly easy, though. |
---|
| 25 | * |
---|
| 26 | * If you want to make a function 'Foo::bar' visible, you should call |
---|
| 27 | * it like this (assuming no C++17 support): |
---|
| 28 | * |
---|
| 29 | * LuaTB<Foo, decltype(&Foo::bar)>::registerFunction<&Foo::bar>( ... ); |
---|
| 30 | */ |
---|
[11519] | 31 | template<FunctionType func> |
---|
| 32 | static void registerFunction(ThisType *_this, lua_State *lua, std::string name); |
---|
| 33 | }; |
---|
| 34 | |
---|
| 35 | // We need to include all type-dependant template implementations, because the |
---|
[11673] | 36 | // compiler needs to know for which types it has to instantiate those. |
---|
[11519] | 37 | #include "luatb.ipp" |
---|
| 38 | |
---|
| 39 | #endif // LUATB_H |
---|
Note: See
TracBrowser
for help on using the repository browser.