[Xapian-tickets] [Xapian] #593: [patch] Lua binding: check that module import is correct
Xapian
nobody at xapian.org
Tue Apr 3 09:48:54 BST 2012
#593: [patch] Lua binding: check that module import is correct
-----------------------------------+----------------------------------------
Reporter: istr | Owner: olly
Type: enhancement | Status: assigned
Priority: normal | Milestone: 1.3.1
Component: Xapian-bindings (Lua) | Version: 1.2.9
Severity: normal | Keywords:
Blockedby: | Platform: All
Blocking: |
-----------------------------------+----------------------------------------
Comment(by istr):
Yes, sorry for the confusion. I did not realize a side effect in the swig
binding of the -nomoduleglobal option in swig initially.
In fact require in Lua 5.1 does both for the vast majority of modules
available:[[BR]]
- return the module as a table[[BR]]
- register the module table within the current global environment[[BR]]
If you want to use xapian in your own lua module, you need require to
return the module table to be able to create a reference within the
module's global environment.
Cf.[[BR]]
http://www.lua.org/manual/5.1/manual.html#2.9 (Environments)[[BR]]
http://www.lua.org/manual/5.1/manual.html#pdf-require (Require)[[BR]]
The problem with the -nomoduleglobal option is, that some functionality of
the swig binding expects to find the module in the current global
environment 'xapian' (a bug that is not easy to fix: you need to enhance
the userdata and improve the encapsulation of the C/Lua "objects"). So it
is best to check that {{{ require'xapian' }}} registers the module in the
current global environment AND returns the module table.
Life would be much easier here if swig used the modern luaL_register /
luaI_openlib method (lauxlib.c since Lua 5.1) and would not use its own
registry method meant to be backwards compatible with Lua 5.0.
As for the licencse: the patch is public domain, you may use it at
whatever license you want (GPLv2, GPLv3, MIT, whatever)
--
Ticket URL: <http://trac.xapian.org/ticket/593#comment:6>
Xapian <http://xapian.org/>
Xapian
More information about the Xapian-tickets
mailing list