Tomasu / LuaGlue

C++11 Lua 5.2 Binding Library
zlib License
79 stars 22 forks source link

Namespace support #6

Open JMLX42 opened 10 years ago

JMLX42 commented 10 years ago

Hello,

I would like to add support for namespaces in LuaGlue. My goal is to make it possible to have this C++ namespaced class:

minko::scene::Node

declared in lua as:

minko.scene.Node

The proper way to do this would be to inject the following Lua code:

minko = {};
minko.scene = {};

Now it would be cool to have a Namespace function (comparable to your Class and Method functions). How can I add that?

Maybe calling that Namespace automatically when the class name passed to Class() has dot characters could be cool too...

Tomasu commented 10 years ago

Namespaces in C++ are syntax sugar. I don't think there's any good way for me to automatically pull out the namespace information.

I can provide a bit of manual "sugar" like the Class method, but call it Namespace("namespace name here"). I was actually thinking about doing that at one point.

something like:

glue.Namespace("minko").Namespace("scene").Class<Node>("Node")     // ...

The only reason I didn't add it, is it wasn't a priority.

Just re-read your comment, I could potentially parse out the namespace info from the class name. I might look into that too. but parsing that out would add some overhead to every Class() call.