bennyxqg / lua-alchemy

Automatically exported from code.google.com/p/lua-alchemy
0 stars 0 forks source link

require() does not work for supplyFile()'d modules #148

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
From the mailing list user Dodo:

- First I download a zip file with multiple *.lua files in it, unzip
it and loop over its contents calling

myLuaAlchemy.supplyFile(zipfile.filename, zipfile.content)

- Second I trigger the main project file by calling

myLuaAlchemy.doFile("main.lua");

So far so good, the main.lua file executes without problems, but if I
hit a require 'otherfile' in main.lua alchemy reports:

main.lua:1: module 'otherfile' not found:
       no field package.preload['otherfile']
       no file './otherfile.lua'
       no file '/usr/local/share/lua/5.1/otherfile.lua'
       no file '/usr/local/share/lua/5.1/otherfile/init.lua'
       no file '/usr/local/lib/lua/5.1/otherfile.lua'
       no file '/usr/local/lib/lua/5.1/otherfile/init.lua'
       no file './otherfile.so'
       no file '/usr/local/lib/lua/5.1/otherfile.so'
       no file '/usr/local/lib/lua/5.1/loadall.so'

Original issue reported on code.google.com by aglad...@gmail.com on 23 Jun 2011 at 9:30

GoogleCodeExporter commented 9 years ago
Currently supplyFile() does not expose files to the require()
function. That's an oversight, thanks for pointing to it. I will fix
that in the next release (sadly, not earlier than the end of the next
week; patches are welcome).

Meanwhile, the simplest way to workaround this is probably to load
your files manually with loadfile(), get the module tables and put
them to the package.loaded global table (key is to be the module
name).

The proper way to fix the stuff is to implement module loader instead
and add it to package.loaders table (probably inserting it after the
table's first element).

You may also try changing package.path to contain "builtin://?.lua"
among other paths before you try to do any require() calls. This
*might* also work — but I'm a bit rusty on that part of Lua
implementation to say for sure.

See the Lua manual entries on the mentioned package.* names for
details. Also it is a good idea to search lua-users Wiki for the same
names (lua-users.org/wiki/FindPage).

Original comment by aglad...@gmail.com on 23 Jun 2011 at 9:30

GoogleCodeExporter commented 9 years ago
The mailing list thread: 
http://groups.google.com/group/lua-alchemy-dev/browse_thread/thread/2cb32459fb17
135d

Original comment by aglad...@gmail.com on 23 Jun 2011 at 9:31

GoogleCodeExporter commented 9 years ago
Do you have trunk or something with this issue fixed?
regards

Original comment by zaynya...@gmail.com on 11 Jul 2011 at 11:19

GoogleCodeExporter commented 9 years ago
Sorry, not yet :( A bit overwhelmed by work.
Will try to figure something out ASAP.
Meanwhile, patches are welcome.

Original comment by aglad...@gmail.com on 11 Jul 2011 at 4:09

GoogleCodeExporter commented 9 years ago
ok, will try to figure it out.

Original comment by zaynya...@gmail.com on 11 Jul 2011 at 6:50

GoogleCodeExporter commented 9 years ago
https://github.com/zaynyatyi/lua-alchemy
started some workaround here
few functions added (if you need list, tell me (all of them in lua-wrapper.gg. 
at the end of file)). and dummy require wrapper function.
For now it doesn't check if you already imported package, but i don't need it 
for now.

Original comment by zaynya...@gmail.com on 26 Jul 2011 at 6:17