[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lua-l
Subject:    Re: context in error handler
From:       Gaspard Bucher <gaspard () teti ! ch>
Date:       2012-01-25 16:53:22
Message-ID: CAOyBgAAPVwHr3Z57Q47QjcLM=hpbBLjbe2Ld2mywTOnuB_hsTQ () mail ! gmail ! com
[Download RAW message or body]

On Wed, Jan 25, 2012 at 2:42 PM, Gaspard Bucher <gaspard@teti.ch> wrote:

> Hi List !
>
> I am trying to prepare an error function before executing a callback from
> C++. The callback uses it's own lua thread with the following stack (just
> before the call):
>
> <self> <err_func> <func> <self> <...>
>
> If func(self, ...) fails, I would like to be able to find the "self" table
> back in the error function. Is this possible ? Do I have to create a
> different function for each object with an upvalue ?
>
> -- Ideal code
> function err(self, msg)
>   -- ...
> end
>

Just a note to say that I managed to have my error handler work by creating
an error function that has my "self" context as upvalue. This means that
all objects with Callbacks now have:

- userdata env (to point to lua thread and avoid gc of thread)
- lua thread
- error function
- self table

I will do a little more testing and ensure memory management is correct and
then the code will be in Dub 2.1.

Cheers,

Gaspard

[Attachment #3 (text/html)]

<br><br><div class="gmail_quote">On Wed, Jan 25, 2012 at 2:42 PM, Gaspard Bucher \
<span dir="ltr">&lt;<a href="mailto:gaspard@teti.ch">gaspard@teti.ch</a>&gt;</span> \
wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex"> Hi List !<div><br></div><div>I am trying to prepare an \
error function before executing a callback from C++. The callback uses it&#39;s own \
lua thread with the following stack (just before the call):</div><div><br></div><div>

&lt;self&gt; &lt;err_func&gt; &lt;func&gt; &lt;self&gt; \
&lt;...&gt;</div><div><br></div><div>If func(self, ...) fails, I would like to be \
able to find the &quot;self&quot; table back in the error function. Is this possible \
? Do I have to create a different function for each object with an upvalue ?</div>

<div><br></div><div>-- Ideal code</div><div>function err(self, msg)</div><div>  -- \
...</div><div>end</div></blockquote><div><br></div><div>Just a note to say that I \
managed to have my error handler work by creating an error function that has my \
&quot;self&quot; context as upvalue. This means that all objects with Callbacks now \
have:</div> <div><br></div><div>- userdata env (to point to lua thread and avoid gc \
of thread)</div><div>- lua thread</div><div>- error function</div><div>- self \
table</div><div><br></div><div>I will do a little more testing and ensure memory \
management is correct and then the code will be in Dub 2.1.</div> \
<div><br></div><div>Cheers,</div><div><br></div><div>Gaspard</div></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic