Jump to content
NewPalette

require

Recommended Posts

I'm just starting out with scripting in Leadwerks, having had a fair bit of experience with Love2d, and I'm having trouble with some standard Lua functions that I think should be working.

 

In particular, I'm having trouble loading modules using the require function. I see people using the require function in examples, but when I try it I get "attempt to call global 'require' (a nil value)".

 

It's as though the Lua standard libraries aren't loaded. Is there something I'm missing?

 

Thank you, ye more-experienced-than-me, for any help.

Share this post


Link to post

In LE use:

 

import "path/path/file.lua"

 

If I recall the LE environment isn't 100% exactly the same as the default Lua environment and require I think is one of those changes.

Share this post


Link to post

I see...

 

import seems to work essentially by dumping the included script in place into the file that is using it. In Lua, it is possible, for example, to require a binary module, i.e. one distributed as a DLL. I was hoping to dynamically load http://moonscript.org/ modules, but the main moonscript module is distributed as a DLL that has to be required. Is there no way to use a binary Lua module within LE?

 

Thanks.

Share this post


Link to post

In this case you would want to use lua ffi. http://luajit.org/ext_ffi.html it allows you to directly load dlls and their C headers, but odds are you will have alot of work ahead of you.

 

Eh, I'm afraid I haven't made my point clear. Moonscript is a lua-targeted programming language, that comes with a DLL which contains a Lua module that allows you to dynamically compile and load Moonscript classes. So, what I'm trying to do isn't really load win32 binaries naively, I'm trying to do something that can already be done in Lua without any additional fanciness, since the "require" function can in fact load modules that are contained within binaries in this fashion. It seems this is just a function that is omitted from LE's Lua implementation.

Share this post


Link to post

If you are using the Steam version try to turn off the sandbox mode. If you don't know how to do that then search the forums here for sandbox mode. Maybe that'll help.

Share this post


Link to post

If you are using the Steam version try to turn off the sandbox mode. If you don't know how to do that then search the forums here for sandbox mode. Maybe that'll help.

 

YES YES! That's done it. Thank you so much.

Share this post


Link to post

If you are using the Steam version try to turn off the sandbox mode. If you don't know how to do that then search the forums here for sandbox mode. Maybe that'll help.

 

Just a quick note. Sandbox is on by default in standalone builds as well. Go to Tools -> Options -> Sandbox Lua and remove the check mark.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...