Questions tagged [lua-loadfile]

7 questions
9
votes
3 answers

Loadfile without polluting global environment

How can I load a file of lua tables and variables without polluting the global environment? Since doing a loadfile and running it just loads everything in the global space and may overwrite something else which I don't want.
Milind
  • 415
  • 8
  • 24
5
votes
1 answer

Loading a file and returning its environment

I'm attempting to do the following : (include() code below) File1.lua A = 5 File2.lua file1 = include(File1.lua) A = 1 print(A) -- 1 print(file1.A) -- 5 i've found exactly what i'm looking for but in lua 5.1 here : Loadfile without polluting…
TomB
  • 53
  • 3
4
votes
1 answer

Opening Lua Files in Interactive Mode

I am beginning to learn Lua on my own with basically no prior programming knowledge. I understand the basics of types, functions, tables, etc. But in following the Lua tuts at Lua.org, I'm currently on the "Modules Tutorial" and am having issues…
Pwrcdr87
  • 935
  • 3
  • 16
  • 36
2
votes
2 answers

Lua loadfile not finding a file

I had some lua code with the following line: JSON = loadfile("JSON.lua")() The file JSON.lua is in the same directory as the lua code that line came from. This code worked for me for a while, and then, without my changing either the lua source, or…
Lolo
  • 3,935
  • 5
  • 40
  • 50
1
vote
1 answer

How to call a function from moonscript in lua?

I've got a moon script code like this: hello = (name) -> print "Hello #{name}!" And i want to use it in my lua code using moonscript.loadfile how should i do something like that?
AmirhCo
  • 13
  • 1
  • 6
1
vote
1 answer

Lua 5.1 setfenv() table still loading in global space

I've been trying to work with setfenv() in order to load a chunk into an environment outside of the global environment but I'm having a little trouble. The following is the code I'm running: -- main.lua function SandboxScript(scriptTable,…
OxCantEven
  • 629
  • 4
  • 9
1
vote
4 answers

Load .dat file and read

I have text .dat file and I load this file from my main class and read in my DataReader class. but I get errors that i have to change my modifier to static. I can't do that because it is required to be non-static. I am stuck here and not sue if my…
Dani
  • 73
  • 1
  • 3
  • 9