Package: swig
Version: 1.3.33-3
Severity: normal
It's standard practice in modern Lua for packages to arrange for the
module's table to be returned from require (as well as being added to
the global environment). People tend to rely on this behavior, and it's
idiomatic to load / use a module with code like:
the_mod = require "..."
the_mod.some_function (1,2,3)
Swig-generated Lua modules don't seem to follow this convention; instead
they seem to return a string (which is fairly useless).
For instance, if I use swig on the following swig input file "foo.swg":
%module foo
%{
char *hi_mom () { return "hi mom!"; }
%}
char *hi_mom ();
and I compile it with:
$ swig -c++ -lua foo.swg
% g++ -shared foo_wrap.cxx -I/usr/include/lua5.1 -o foo.so
then the following Lua session shows the swig module's behavior compared
to the module "lpeg", which illustrates the standard behavior:
$ lua
Lua 5.1.3 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> the_swig_mod = require "foo"
> print (the_swig_mod)
foo
> print (the_swig_mod.hi_mom)
nil
> the_lpeg_mod = require "lpeg"
> print (the_lpeg_mod)
table: 0x8078d48
> print (the_lpeg_mod.match)
function: 0x806de20
>
Notice that loading the swig module simply returns a string from the
call to require, whereas the lpeg module returns the actual table.
Here's a quote from the book "Programming In Lua 2", which describes the
desired behavior:
From the user point of view, a module is a library that can be loaded
through require and that defines one single global name containing
a table. Everything that the module exports, such as functions and
constants, it defines inside this table, which works as a namespace.
A well-behaved module also arranges for require to return this table.
Thanks,
-Miles
-- System Information:
Debian Release: lenny/sid
APT prefers unstable
APT policy: (990, 'unstable'), (500, 'testing'), (500, 'stable'), (1,
'experimental')
Architecture: i386 (i686)
Kernel: Linux 2.6.22.7 (PREEMPT)
Locale: LANG=ja_JP.UTF-8, LC_CTYPE=ja_JP.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages swig depends on:
ii libc6 2.7-8 GNU C Library: Shared libraries
ii libgcc1 1:4.3-20080219-1 GCC support library
ii libstdc++6 4.3-20080219-1 The GNU Standard C++ Library v3
swig recommends no packages.
-- no debconf information
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]