making load() work with an environment?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
konacake
Prole
Posts: 11
Joined: Mon Mar 03, 2014 4:35 am

making load() work with an environment?

Post by konacake »

I'm trying to add scripting to my love project, so I'm using load() (not love.load()) to evaluate lua code. Problem is, I cannot for the life of me figure out how to give it an environment, or chuck if you will. In fact, I'm not even sure if I'm using it correctly at all. Is anyone familiar with load()? I appreciate any help. I've included the section of code (very sloppy, I code clean after I finish it) as well as the output it gives me (which I do not understand, sadly).
User avatar
norubal
Party member
Posts: 137
Joined: Tue Jan 15, 2013 5:55 am

Re: making load() work with an environment?

Post by norubal »

It seems like link is dead, can you attach your .love file?
and welcome to the forum, welcome aboard :ultraglee:
User avatar
konacake
Prole
Posts: 11
Joined: Mon Mar 03, 2014 4:35 am

Re: making load() work with an environment?

Post by konacake »

The links work for me, but yeah attaching the .love file would be a better idea, I should have just done that. Hopefully it'll be attached to this post. The code is in the terminal.lua file. Also try rapidly right clicking it's mildly amusing.
Attachments
test1.love
(612.73 KiB) Downloaded 151 times
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: making load() work with an environment?

Post by slime »

Lua 5.1 (which is what LuaJIT is based on, and LÖVE uses LuaJIT) uses different functionality for environments than Lua 5.2 and 5.3. You'll need to call setfenv on the function returned by load, before calling that returned function.
User avatar
konacake
Prole
Posts: 11
Joined: Mon Mar 03, 2014 4:35 am

Re: making load() work with an environment?

Post by konacake »

Thank you slime. I've just tried that, but it doesn't seem to be helping. Love2D itself gives the error that setfenv wants a value instead of nil when I simply type a symbol name, when I type an expression like "var = 10" the terminal continues to say it expects an <EOF>, and I have no idea how to fix that one. If possible, can I inconvenience anyone for some sample code? I really don't think I'm doing this right, and I tried looking it up online for hours.

EDIT: Okay that actually does work, so I have a working environment now. But I still have this <eof> problem. Does anyone know why it's doing that?

EDIT2: Okay I fixed it never mind, I just had it check for "=" in the expression and if it's in there, just omit the "return" part of the string. Thank you for all your help guys!
Post Reply

Who is online

Users browsing this forum: No registered users and 164 guests