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.
pcAll
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: pcAll
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...
I should check my code more thoroughly before releasing...
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: pcAll
New version (yeah, I know...), this one is a bit better commented and supports functions AND tables instead of just tables.
Code example:
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
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" :
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) )
My projects current projects : dragoon-framework (includes lua-newmodule, lua-provide, lovemodular, , classcommons2, and more ...)
Who is online
Users browsing this forum: No registered users and 2 guests