lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Thanks for letting me know this difference. This is good. I think the example programs on the website should be updated to reflect this.

Thanks,
Milind



On Mon, Mar 31, 2014 at 11:02 PM, Peng Zhicheng <pengzhicheng1986@gmail.com> wrote:
On 04/01/2014 05:10 AM, Milind Gupta wrote:
Hi,
      I had been using luasql in luaforwindows. One difference I see is that in Lua For windows require("luasql.sqlite3") would create a table named luasql in the global space. In Luadist this does not happen and you have to take the table returned by the require statement and use that.
         The luasql website examples assume that the require statement creates a global table called luasql. So something has to be updated/corrected. Would LuaDist be updated?

Thanks,
Milind



this behavior is not to be _CORRECTED_; it is meant/expected to be like this.

modules are not supposed to inject values into the global environment any more in Lua 5.2.
the user code wanting to use a module can bind the value returned by `require' to any variable.
user code is now encouraged to be written like this:

  local I_name_it = require "the.orignial.module.name"


if you have no special reason to stick with Lua 5.1, I suggest to use Lua 5.2 and write code
according to the Lua 5.2 convention. in most cases, the user code shouldn't need to much effort
to modify or update.

in the case of `luasql', just change the line

  require "luasql.sqlite3"

to

  local sqlite3 = require "luasql.sqlite3"

and then replace the old `luasql.sqlite3' with the new 'sqlite3' in the code

iirc, you'll never need the `luasql' table itself.


best regards.