|
From: Ervin H. <ai...@gm...> - 2016-10-23 18:48:31
|
HI Alan,
many thanks for your answer,
On Sun, Oct 23, 2016 at 10:26:49AM -0700, Alan W. Irwin wrote:
> On 2016-10-22 19:43+0200 Ervin Hegedüs wrote:
>
> >Hi,
> >
> >I'ld like to make a library for Lua from a C code. There is a variable,
> >which has int[10] type.
[...]
> >I'm trying this way:
> >
> >%typemap(out) int [ANY] {
> > int len,i;
> > len = $1_dim0;
> > lua_createtable (L, len, 0);
> > for(i=0; i<len; i++) {
> > lua_pushinteger(L, (lua_Integer)$1[i]);
> > }
> > lua_settable(L, (-1)*(len+1));
> >}
> >
> >but in Lua script shows only this:
> >
> >nil
> >
> >What'em I missing? Could anybody helps in this problem?
>
> Hi Ervin:
>
> I can't help you with any details because the swig-generated PLplot lua
> binding is not my code, but PLplot uses the following typemap for input
> integer arrays.
>
> //--------------------------------------------------------------------------
> // PLINT arrays
> //--------------------------------------------------------------------------
>
> // With preceding count
> %typemap ( in ) ( PLINT n, const PLINT * Array )
> {
> $2 = (PLINT *) LUA_get_int_num_array_var( L, $input, &$1 );
> if ( !$2 )
> SWIG_fail;
> Alen = $1;
> }
> %typemap ( freearg ) ( PLINT n, const PLINT * Array )
> {
> LUA_FREE_ARRAY( $2 );
> }
>
> Note, that PLINT is a macro defining a specific integer type for
> PLplot, and we use redacted argument lists (where the array dimension
> is not specifically mentioned in the Lua call because that information
> is already available via the Lua array). That redaction is why you
> see the "n" argument included above. Also, LUA_get_int_num_array_var
> and LUA_FREE_ARRAY are much! more complex macros that we #define to
> vastly simplify implementing the above typemap and many others that we
> use. Most of PLplot array use in argument lists is for input arrays
> like above, but some of our typemaps are also for output arrays. So
> the above is just a tiny part of the picture but should be enough so
> you will know whether you want to look further at our Lua binding to
> get some ideas. You can find the above typemap in
> bindings/lua/plplotluac.i in the working directory of our git
> repository which you can access following the prescription at
> <https://sourceforge.net/p/plplot/plplot/ci/master/tree/>.
thanks for detailed notes - may be I'll see the source of Plplot
to understand, how Lua binding works.
> Just for your information the core PLplot library is written in C; we
> generate our Python, Java, Octave, and Lua bindings of that library
> using swig; and we confirm with tests that our standard set of ~30
> examples written in all those languages produce identical plot results
> as our standard set of those same examples written in C. So we are
> pretty happy with the completeness and accuracy of our swig-generated
> bindings!
right, thanks for this info too.
Now I'ld have to solve this problem in Swig for Lua, there are
too much bindings had written and tested with it.
If everything works as well (and I'll have enough time :)), I'll
see that depptly.
Anyway, there are several other problems in Lua binding - see my
other e-mails.
Many thanks again,
a.
--
I � UTF-8
|