Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How are lua's requires working? #13

Open
caioviel opened this issue Aug 31, 2012 · 4 comments
Open

How are lua's requires working? #13

caioviel opened this issue Aug 31, 2012 · 4 comments

Comments

@caioviel
Copy link

Hello,

This project is really great!

I'm using it in WebNCL, a web-based implementation of NCL presentation machine. NCL is a multimedia language and one of its features is support fo Lua scripts.

We'd had great success in using the lua.js in your project so far, but I'm facing a problem with requires. I really don't how they work.

@mherkender
Copy link
Owner

EDIT: I must've been tired or something when I wrote this. Cleaned it up a bit.

Sorry for the slow response, busy week for me. require should work in a similar way to regular Lua, although modules must be set up manually before use.

A module needs to call module to set itself up, or can be set up more directly in Javascript by using lua_createmodule, if you prefer.

If you're having any other problems, I'd be happy to help.

@kyleconroy
Copy link
Contributor

Lua's module function has design flaws and shouldn't be used. I create modules using the table method.

-- mymodule.lua
local M = {} -- public interface

-- private
local x = 1
local function baz() print 'test' end

function M.foo() print("foo", x) end

function M.bar()
  M.foo()
  baz()
  print "bar"
end

return M

We should make sure that these style of modules also work with require

@mherkender
Copy link
Owner

I did design for it, although looking at it, it could be improved.

Basically when you return like that, it overrides what's originally returned (_G) in the generated JS function. Since initializing modules is currently done manually in lua.js, the table method just replaces using the return value of the generated script and lua_createmodule.

@caioviel
Copy link
Author

caioviel commented Oct 9, 2012

I'm working in another project right now, so my NCL/Lua player is kinda inactive.

I was trying to run a NCL/Lua sample that uses multiple Lua files (the description is in portuguese).

I could not "import" the other files used in the sample. Is it not implemented yet, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants