Page 1 of 1

pcAll

Posted: Fri Feb 27, 2009 12:25 pm
by bartbes
I know, I know, but wait until I explain the name:
pcall + All -> pcAll, got it?

Well, basically I've explained the entire purpose with that sentence, this is a tiny lib (if you can call it that) that can convert every table into one where every function is pcalled. So if you don't like big screaming (blue) errors, try this.

I'm open for suggestions, so if you want to have anything changed, ask me.

Further information is posted on request (because I don't want to write an entire story, just so everyone skips it).

Let me explain some more:
pcall is a standard lua function meaning: call in 'protected mode'.
Protected mode means that all errors are catched and processed silently instead of just stopping (in LÖVE with a Blue Screen Of Dying LÖVE).
pcAll is there so you can wrap tables (and now functions) so everytime you call them (or rather the new handle returned by pcAll) the function gets pcalled instead.
This means that every wrapped function then returns a boolean (true/false) saying if the function succeeded and the normal output or the error (as returned by lua).

Hope that's enough.

Re: pcAll

Posted: Fri Feb 27, 2009 5:03 pm
by bartbes
Sorry for the three people who had already downloaded it, I forgot an important part. (it didn't set the variables in the original when they were set in the new one)
I should check my code more thoroughly before releasing...

Re: pcAll

Posted: Sat Feb 28, 2009 2:28 pm
by bartbes
New version (yeah, I know...), this one is a bit better commented and supports functions AND tables instead of just tables.
Code example:

Code: Select all

mytable = {}
mytable.string = "Test variable"
function mytable.give_error()
    error("This always errors")
end

function myfunction()
    error("And this as well")
end

wtable = pcAll(mytable)
wfunction = pcAll(myfunction)

mytable.give_error()    --This will give the error, as expected
myfunction()            --This too

wtable.give_error()     --Returns false and the error, but continues
wfunction()             --Same

--Something else, this all works
print(wtable.string)    --Prints "Test variable"
wtable.string = "Changed variable"
--Variable was changed in the table returned by pcAll, this actually sets the value in the original table
print(mytable.string)   --Prints "Changed variable"

Re: pcAll

Posted: Tue Mar 24, 2009 8:16 pm
by TsT
You current version work good with lua 5.1 but not with lua 5.0.

If you want to be compatible with the both change the call of "..." to "arg" :

Code: Select all

--- pcall/pcAll.lua     (original)
+++ pcall/pcAll.lua     (working copy)
@@ -43,7 +43,7 @@
 end

 function wrap:__call(...)              --The function where the original is pcalled
-       return pcall(self.f, ...)
+       return pcall(self.f, arg)
 end

 function pcAll_private_mt:__call(t)    --This is to make it possible to use the table pcAll as a function (example: wrap_table = pcAll(orig_table) )

Re: pcAll

Posted: Tue Mar 24, 2009 9:35 pm
by bartbes
Fair enough. But I do have to ask, why bother making it 5.0 compatible? New software should be written on 5.1, and this still is the LÖVE forums, if it works with LÖVE it's good?