io.write() does not work on device

print() and io.write() both work on the simulator. But on device, only print() works. io.write() outputs nothing neither to the Xcode console nor the Android console.

io.output():setvbuf(‘no’)
print(“This line will show on both simulator and device.”)
io.write(“This line will show on simulator, but not on device.\n”);

I need io.write() for a table.print() debug function. Without it, I am unable to dump Lua tables to the console, which makes debugging very difficult.

I am pretty sure io.write() worked on device before. Corona staff: Did you introduce a bug here? Or can you tell me if there’s any changes I need to make to my code?

[import]uid: 73434 topic_id: 34304 reply_id: 334304[/import]

I’ve never tried to use io.write like that. However, with iOS 6.0, Apple broke how content written to STDOUT shows up in the console log (it doesn’t). We patched print to use NS_LOG to write things out. I suspect that io.write() wasn’t patched for this purpose.

Anyway, to solve your immediate problem, I’m rather fond of this block of code (taken from the Community code)

function M.print\_r ( t )   
 local print\_r\_cache={}  
 local function sub\_print\_r(t,indent)  
 if (print\_r\_cache[tostring(t)]) then  
 print(indent.."\*"..tostring(t))  
 else  
 print\_r\_cache[tostring(t)]=true  
 if (type(t)=="table") then  
 for pos,val in pairs(t) do  
 if (type(val)=="table") then  
 print(indent.."["..pos.."] =\> "..tostring(t).." {")  
 sub\_print\_r(val,indent..string.rep(" ",string.len(pos)+8))  
 print(indent..string.rep(" ",string.len(pos)+6).."}")  
 elseif (type(val)=="string") then  
 print(indent.."["..pos..'] =\> "'..val..'"')  
 else  
 print(indent.."["..pos.."] =\> "..tostring(val))  
 end  
 end  
 else  
 print(indent..tostring(t))  
 end  
 end  
 end  
 if (type(t)=="table") then  
 print(tostring(t).." {")  
 sub\_print\_r(t," ")  
 print("}")  
 else  
 sub\_print\_r(t," ")  
 end  
 print()  
end  

print_r is the PHP way of dumping a table, ergo it’s name. I tuck this puppy away in a file I copy from project to project so I always have it available. Joshua also added a new printTable() function in the Google Push Notification sample app in build 993 that will do the same thing.

[import]uid: 199310 topic_id: 34304 reply_id: 136373[/import]

So Apple’s the culprit. Will just have to avoid io.write() then. Thanks! Case closed. [import]uid: 73434 topic_id: 34304 reply_id: 136374[/import]

I’ve never tried to use io.write like that. However, with iOS 6.0, Apple broke how content written to STDOUT shows up in the console log (it doesn’t). We patched print to use NS_LOG to write things out. I suspect that io.write() wasn’t patched for this purpose.

Anyway, to solve your immediate problem, I’m rather fond of this block of code (taken from the Community code)

function M.print\_r ( t )   
 local print\_r\_cache={}  
 local function sub\_print\_r(t,indent)  
 if (print\_r\_cache[tostring(t)]) then  
 print(indent.."\*"..tostring(t))  
 else  
 print\_r\_cache[tostring(t)]=true  
 if (type(t)=="table") then  
 for pos,val in pairs(t) do  
 if (type(val)=="table") then  
 print(indent.."["..pos.."] =\> "..tostring(t).." {")  
 sub\_print\_r(val,indent..string.rep(" ",string.len(pos)+8))  
 print(indent..string.rep(" ",string.len(pos)+6).."}")  
 elseif (type(val)=="string") then  
 print(indent.."["..pos..'] =\> "'..val..'"')  
 else  
 print(indent.."["..pos.."] =\> "..tostring(val))  
 end  
 end  
 else  
 print(indent..tostring(t))  
 end  
 end  
 end  
 if (type(t)=="table") then  
 print(tostring(t).." {")  
 sub\_print\_r(t," ")  
 print("}")  
 else  
 sub\_print\_r(t," ")  
 end  
 print()  
end  

print_r is the PHP way of dumping a table, ergo it’s name. I tuck this puppy away in a file I copy from project to project so I always have it available. Joshua also added a new printTable() function in the Google Push Notification sample app in build 993 that will do the same thing.

[import]uid: 199310 topic_id: 34304 reply_id: 136373[/import]

So Apple’s the culprit. Will just have to avoid io.write() then. Thanks! Case closed. [import]uid: 73434 topic_id: 34304 reply_id: 136374[/import]