Jump to content

fileGetSize problem


Recommended Posts

Hi, i have problem with fileGetSize and fileRead. I have this code:

local str = fileRead( file, fileGetSize ( file ) or 0 ) 

And i have error

 Bad 'number' pointer 
@ 'fileRead'(2) 

Whats wrong with this?

you are doing something wrong. the code looks fine to me

Link to comment

-- load JSON from file 
function loadJSONData( filename ) 
    local file = fileExists( filename ) and fileOpen( filename, true ) or fileCreate( filename ) 
    local str = fileRead( file, fileGetSize( file ) or 0 ) 
    local t = fromJSON( str ) or {resolution = {}} 
    fileClose( file ) 
    return t 
end 

It's all code of function

Link to comment
-- load JSON from file 
function loadJSONData( filename ) 
    local file = fileOpen( filename, true ) or fileCreate( filename ) 
    local str = fileRead( file, fileGetSize( file ) or 0 ) 
    local t = fromJSON( str ) or {resolution = {}} 
    fileClose( file ) 
    return t 
end 

Link to comment
  
local file = fileExists( filename ) and fileOpen( filename, true ) or fileCreate( filename ) 
  

I'm not sure, I'm assuming that if the file already existed, you would get a TRUE value, and not a file element. You could also fix it by using parentheses

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...