Fixing enums
This commit is contained in:
parent
cad7f86112
commit
1898099620
3 changed files with 55 additions and 45 deletions
|
|
@ -510,14 +510,16 @@ Enums are exported into a class table. For example, given some enums:
|
|||
enum Days { SUNDAY = 0, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY };
|
||||
struct Test {
|
||||
enum { TEST1 = 10, TEST2 = 20 };
|
||||
#ifdef __cplusplus // There are no static members in C language
|
||||
static const int ICONST = 12;
|
||||
#endif
|
||||
};
|
||||
</pre></div>
|
||||
<p>
|
||||
This is 'effectively' converted into the following Lua code:
|
||||
There is a slight difference in behaviour in C mode and C++ model. In C++ mode this is 'effectively' converted into the following Lua code:
|
||||
</p>
|
||||
<div class="targetlang"><pre>
|
||||
> print(example.const.SUNDAY)
|
||||
> print(example.SUNDAY)
|
||||
0
|
||||
> print(example.Test.TEST1)
|
||||
10
|
||||
|
|
@ -525,6 +527,15 @@ This is 'effectively' converted into the following Lua code:
|
|||
12
|
||||
</pre></div>
|
||||
|
||||
<p>In C mode enums from structs are exported into global namespace (due to C Standard). See below:</p>
|
||||
<div class="targetlang"><pre>
|
||||
> print(example.SUNDAY)
|
||||
0
|
||||
> -- See the difference here
|
||||
> print(example.TEST1)
|
||||
10
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
<b>Compatibility Note:</b> Versions of SWIG prior to SWIG-3.0.0 did not generate the class table members above.
|
||||
The following code was the only way to access these constants/enums:
|
||||
|
|
@ -540,17 +551,17 @@ The old-style bindings are still generated in addition to the new ones.
|
|||
If the <tt>-no-old-metatable-bindings</tt> option is used, then these old-style bindings are not generated.
|
||||
</p>
|
||||
<p>
|
||||
However, in C mode, names of enums are not prefixed with names of structure. This is the due to the C Standard.
|
||||
However, in C mode, prefixed names of enums are not exported. There is no sense in having both Test_TEST1 and TEST1 in global namespace.
|
||||
</p>
|
||||
<div class="targetlang"><pre>
|
||||
> print(example.TEST1)
|
||||
10
|
||||
> print(example.ICONST)
|
||||
12
|
||||
> print(example.Test_TEST1)
|
||||
nil
|
||||
</pre></div>
|
||||
<p>
|
||||
It is worth mentioning, that <tt>example.Test.TEST1</tt> and <tt>example.Test_TEST1</tt> are different entities and changing one does not change the other.
|
||||
Given the fact, that these are constantes and they are not supposed to be changed, it is up to you to avoid such issues.
|
||||
Given the fact that these are constantes and they are not supposed to be changed, it is up to you to avoid such issues.
|
||||
</p>
|
||||
<H3><a name="Lua_nn12"></a>26.3.5 Pointers</H3>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue