I used the luac52.exe -o test.txt test.lua
command to made a bytecode of a test.lua
file, named test.txt
. Now, if I open the test.txt
file with Notepad++, it contains some really strange black symbols. Now, how do I load it with the load("abcde", nil, "bt", _ENV)()
command? I need to use the load function specificaly... Should I give a .txt extension?
Thanks
Asked
Active
Viewed 1,437 times
0

Oti Na Nai
- 1,327
- 4
- 13
- 20
-
1Have you looked at the documentation for the [load](http://www.lua.org/manual/5.2/manual.html#pdf-load) function? – Etan Reisner Apr 15 '15 at 16:17
-
1How do you intend on getting the contents of test.txt to the load function? And, .txt is a strange extension for a file that doesn't contain text. Some people use .lub for Lua Bytecode. – Tom Blodget Apr 15 '15 at 17:12
-
I don't know how to copy and paste the contents of .txt into "abcde" text of the load function as, indeed, it isn't a regular text... Even if I use .lub and open it with Notepad++ it has the exact same contents as the .txt though... – Oti Na Nai Apr 15 '15 at 17:59
-
I suspect this question has the [X-Y Problem](http://meta.stackexchange.com/a/233676). The best way to help you is for you to describe what your higher-level goal is and why you are constrained to using `load`. – Tom Blodget Apr 15 '15 at 23:18
1 Answers
1
Use loadfile("test.txt")
instead of load
. This will give you a function that you need to run to execute whatever is in test.txt
.
Or you can use dofile("test.txt")
, which you load and run.
If you really need to use load
, then read the contents of test.txt
into a string and send it to load
.
To read the contents of a file, see Read whole file and print in lua.
-
But I need to use the load function specifically as I mention T_T Is there any way it can be done with load? – Oti Na Nai Apr 15 '15 at 21:20
-
First, thanks for the answers. I used c = f:read("*all") and if I test printing c then only a "LuaR" is printed. Even so, If I use load(c, nil, "bt", _ENV)() then it gives the error attempt to call a nil value... – Oti Na Nai Apr 15 '15 at 23:23
-
`load` expects a function that returns the string or chunk to load. Try `load(function() return f:read "*a" end)` – greatwolf Apr 15 '15 at 23:59
-
Same, I used load(function() return f:read "*a" end, nil, "bt", _ENV)() – Oti Na Nai Apr 16 '15 at 01:28