Fflua Update-adds reference support and fflua update adds reference
Introduction:
Fflua has been released for a while, and many netizens have used it and provided some good feedback. One of them is the support for reference when the c ++ interface is registered to lua. This makes it easier to use.
Original method:
Use the following method to register c ++ classes in fflua:
Class base_t {public: base_t (): v (789) {} void dump () {printf ("in % s a: % d \ n", _ FUNCTION __, v) ;}int v ;};//! Register a base-class function. ctor () is the type of the constructor fflua_register_t <base_t, ctor ()> (ls, "base_t ")//! Register the constructor. def (& base_t: dump, "dump ")//! Register the function of the base class. def (& base_t: v, "v ");//! Register the attributes of a base class
After the c ++ class is successfully registered, the lua code can operate the Class Object Pointer and pass it as a parameter to the c ++ interface:
Void dumy_base (base_t * p) {printf ("in % s begin ------------ \ n", _ FUNCTION _);} fflua_register_t <> (ls ). def (& dumy, "dumy ");//! Register static functions
Some netizens told me that many of the original interfaces use references as parameters. In order to receive the parameters passed by lua, you have to write a new function, which is troublesome, therefore, fflua adds reference support:
Void dumy_base (base_t & p) {printf ("in % s begin ------------ \ n", _ FUNCTION _);} fflua_register_t <> (ls ). def (& dumy, "dumy ");//! Register static functions
Summary:
Latest code:
Https://github.com/fanchy/fflua