Nightmare12 Posted June 26, 2012 Share Posted June 26, 2012 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? Link to comment
qaisjp Posted June 26, 2012 Share Posted June 26, 2012 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
Nightmare12 Posted June 26, 2012 Author Share Posted June 26, 2012 -- 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
qaisjp Posted June 26, 2012 Share Posted June 26, 2012 -- 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
Nightmare12 Posted June 26, 2012 Author Share Posted June 26, 2012 Thanks, it work But what was make this issue? I want to now for the future Link to comment
qaisjp Posted June 26, 2012 Share Posted June 26, 2012 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now