Homebrew [Release] Lua Player Plus 3DS (lpp-3ds) - LUA interpreter for 3DS

  • Thread starter Thread starter Rinnegatamante
  • Start date Start date
  • Views Views 187,229
  • Replies Replies 1,199
  • Likes Likes 35
Yep,I tested with a file with a single 1, and it reads it as string (trying to operate with it returns expected number, got string)

I can think of multiple reasons for your problem.

1. You are not saving your text file in the correct format (ANSI) which allocates 1 byte per character. You can check this by simply looking at the filesize of the file. If it truly is just the character "1", then the file should only be 1 byte.

2. You haven't opened the file correctly in lua, be this not using the right functions, or not specifying the right filepath. The correct code for loading the entirety of a file into a string is:
Code:
file = io.open(System.currentDirectory().."/filename.txt",FREAD)
filesize = io.size(file)
str = io.read(file,0,filesize)
io.close(file)
If you failed to load the file correctly, your tonumber() function should tell you "got nil"

3. You are accessing the wrong string, or using the wrong arguments. Try printing your string with Screen.debugPrint to check if you actually are using the right variable.

4: Assuming the function that's throwing the error is the tonumber line: You're entering a string into the base parameter of tonumber(e [, base]). e must be a string, base must be a number if included.
 
Last edited by HexZyle,
  • Like
Reactions: Seriel
If you're saving the number make sure when you do io.write you change the last parameter to the number of bytes you're writing. A single digit or alphabetical character is 1 byte so if you're writing the number "100" you need to do something like io.write(myFile,0,"100",3).

When you read it make sure you set the offset and size correctly.

@HexZyle's solution will work assuming the number is the only thing written in the file. If there is more data you will have to do some additional work to separate the rest of the text from the number, such as splitting on new lines.
 
Last edited by 0x0wl,
  • Like
Reactions: Seriel
Okay, I learnt that in order to enable the 3D functionality of Lua homebrew you need to enable 3D when Homebrew Launcher is opened, doing so stops the apps from crashing when being called to draw the right eye.

However, no matter what I do, I cannot get the Screen.drawPartialImage to draw for the Right Eye: It only ever draws to the left. Even before when RIGHT_EYE functions were causing hangs, a Screen.drawPartialImage function with a RIGHT_EYE parameter did not (because it drew to the left eye)
 
  • Like
Reactions: Seriel
I 100% sure I'm doing it correctly, (used HxD to check it).
But the point now, it is I'm getting "not enough memory", and I'm sure I didn't fill all the ram.

Well, here is my code (MK7 custom track manager thing):
function getconfig()
local config = io.open(System.currentDirectory().."/config/config.cfg",FCREATE)
local cfgtrack = io.open(System.currentDirectory().."/config/tracknames.cfg",FCREATE)
-- Course order: GBABC, CTRTC, CTRWI1, N64KD, SFCMC
trackn = io.size(config)
local stringtrck = io.read(cfgtrack, 0, io.size(cfgtrack))
local l = 1
tracks = {}
for i in string.gmatch(stringtrck, "%S+") do
tracks[l] = i
l = l + 1
end
if not ( tracks[trackn + 1] == nil) then
System.exit()
end
tracke = {}
for i = 1, trackn, 1 do
tracke = io.read(config, (i+1), 1) -- Get data from config.cfg
end
io.close(config)
io.close(cfgtrack)
return 1
end

config.txt is: 01010
tracknames.txt is: Gagb_BowserCastle1 Gctr_ToadCircuit Gctr_WuhuIsland1 Gn64_KalimariDesert Gsfc_MarioCircuit2

I want to get trackn(number of tracks), tracks(track names on an array), and tracke(enabled or disabled 0 or 1 also as array)


I'm a begginer in lua, so I'm pretty sure my code isn't optimized.
 
Last edited by PabloMK7,
  • Like
Reactions: Seriel
I 100% sure I'm doing it correctly, (used HxD to check it).

If you're going to give us so little info, there's not much more we can do. Unless you write what the error is verbatim, and the code from the referred line, then I'm afraid I can't help you.

If you are 100% sure you are doing it right, does that mean that you believe the program is at fault? If that's the case, then there really isn't anything we can do.
 
Last edited by HexZyle,
  • Like
Reactions: Seriel
If you're getting a not enough memory error, you need to reboot Homebrew Launcher because you have a memory leak that's filled up all the available RAM.
 
  • Like
Reactions: Seriel
Why are you opening with FCREATE? It overwrites the existing file.

Edit nevermind. I thought it did.
 
Last edited by 0x0wl,
  • Like
Reactions: Seriel
That's exactly what I thought it did, was just in the middle of trying to recreate it to confirm

EDIT: Actually it doesn't seem to overwrite the file in my program...
 
Last edited by HexZyle,
  • Like
Reactions: Seriel
I don't know if this is related, but I had a Not Enough Memory error that was caused because file.size was returning a near infinite number for some reason. Since I was using that size in file.read the interpreter was trying to allocate too much memory. Not sure what was causing file.size to return a crazy number, I wasn't doing anything strange as far as I know, it would sometimes just blow up.
 
  • Like
Reactions: Seriel
I don't know if this is related, but I had a Not Enough Memory error that was caused because file.size was returning a near infinite number for some reason. Since I was using that size in file.read the interpreter was trying to allocate too much memory. Not sure what was causing file.size to return a crazy number, I wasn't doing anything strange as far as I know, it would sometimes just blow up.

mmmhhh size is returned as a LUA_NUMBER (so a double in C/C++). It should be big enough to contain big numbers.
 
  • Like
Reactions: Seriel
string module and all basic modules of LUA 5.3.0 are all available on lpp-3ds.

What line of your code returns the "not enough memory" error?

It doesn't say, just: "Not enough memory", and anything more.

I don't know if this is related, but I had a Not Enough Memory error that was caused because file.size was returning a near infinite number for some reason. Since I was using that size in file.read the interpreter was trying to allocate too much memory. Not sure what was causing file.size to return a crazy number, I wasn't doing anything strange as far as I know, it would sometimes just blow up.

Maybe, I'll try to replace io.size with the lenght of the file, if it doesn't say it anymore, there is the problem.

EDIT: Yep, the problem is caused by io.size
 
Last edited by PabloMK7,
  • Like
Reactions: Seriel
mmmhhh size is returned as a LUA_NUMBER (so a double in C/C++). It should be big enough to contain big numbers.

The file was less than 100 bytes long, and io.size returned something like 5.12312 E56 or something crazy huge like that. Not sure why it happens.
 
  • Like
Reactions: Seriel

Site & Scene News

Popular threads in this forum