swig/swig — pull request #90 by v-for-vandal (2013-09-25 11:11:46+00:00)
Title: Native extend

This is more of a preliminary pull request.
It is an attempt to implement this "request" - http://stackoverflow.com/questions/16360012/swig-lua-extending-extend-class-with-native-is-it-possible-to-add-native

The problem is that some languages doesn't have a concept of a class and thus have no concept of inheritance. If I want to extend my class Spam bindings with some new method written in target language, then in Python I can, for example:
1. rename C++ class Spam to Spam_base when wrapping
2. inherit python class Spam from Spam_base
3. add necessary method
```
class Spam( Spam_base):
def my_new_method:
pass
```

Voilà - user is presented with extended interface.

Now, this thing can't be done in Lua. There is no concept of inheritance in Lua and current Lua bindings doesn't implement one. Let's say you have
```
class A {};
class B : public A {};
```
If you want to add some lua-method "my_new_method" to class A and all its descendants you could, for example, forcefully insert it into lua class metatable during or after library initialization. The problem is that in current implementation class B contains a copy of class A metatable (not a reference to it) and thus will not be affected by the change.

There are at least 2 ways to solve this:
1. Severely change current implementation of lua bindings.
2. Allow usage of %native inside %extend directives.

%native inside %extend behave as methods that need no wrapping. They are added directly to appropriate arrays without any name mangling etc. They can't be overloaded and can't participate in any other overload.

This pull reques provides _preliminary_ implementation of the second way. It is not fully finished. I would like to recive some comments on whether it would be accepted at all, is this a correct strategy or should the lua bindings be rewriten (not sure I am ready to do this) etc.

Thanks in advance.