Yes, sorry. Just copy&paste from iuplua.c

Best,
Scuri


On Sat, Jul 11, 2015 at 11:45 AM, Milind Gupta <milind.gu...@gmail.com>
wrote:

> I just had to change iup_handle in lua_getmetatable to "iupHandle" to work
> in my code.
>
> On Sat, Jul 11, 2015 at 7:31 AM, Milind Gupta <milind.gu...@gmail.com>
> wrote:
>
>> Looks good.
>>
>> Thanks,
>> Milind
>>
>> On Sat, Jul 11, 2015 at 7:26 AM, Antonio Scuri <sc...@tecgraf.puc-rio.br>
>> wrote:
>>
>>> How about:
>>>
>>> int iuplua_isihandle(lua_State *L, int pos)
>>> {
>>>   int ret = 0;
>>>   if (lua_getmetatable(L, pos))   /* t2 = metatable(stack(pos)) */
>>>   {
>>>     lua_pushstring(L, iup_handle);
>>>     lua_gettable(L, LUA_REGISTRYINDEX);  /* t = registry["iupHandle"] */
>>>
>>>     if (lua_rawequal(L, -2, -1))   /* check (t2==t)? */
>>>       ret = 1;
>>>
>>>     lua_pop(L, 2);   // Pop registry["iuphandle"] and the metatable
>>>   }
>>>
>>>   return ret;
>>> }
>>>
>>> Best,
>>> Scuri
>>>
>>>
>>> On Sat, Jul 11, 2015 at 2:44 AM, Milind Gupta <milind.gu...@gmail.com>
>>> wrote:
>>>
>>>> It works good. I modified it a little to balance the stack:
>>>>
>>>> int iuplua_isihandle(lua_State *L, int pos)
>>>> {
>>>>     int x = lua_getmetatable(L, pos);  /* t2 = metatable(stack(pos)) */
>>>>     lua_pushstring(L, "iupHandle");
>>>>     lua_gettable(L, LUA_REGISTRYINDEX);  /* t = registry["iupHandle"] */
>>>>     if (lua_rawequal(L, -2, -1))   /* check (t2==t)? */
>>>>     {
>>>>         lua_pop(L, 2);
>>>>         return 1;
>>>>     }
>>>>     else
>>>>     {
>>>>         if (x)
>>>>             lua_pop(L,2);   // Pop registry["iuphandle"] and the
>>>> metatable
>>>>         else
>>>>             lua_pop(L,1);   // Pop registry["iuphandle"]
>>>>         return 0;
>>>>     }
>>>> }
>>>>
>>>>
>>>> On Fri, Jul 10, 2015 at 4:50 PM, Milind Gupta <milind.gu...@gmail.com>
>>>> wrote:
>>>>
>>>>> Thanks,
>>>>>              I will try it out tonight.
>>>>>
>>>>> Milind
>>>>>
>>>>>
>>>>> On Fri, Jul 10, 2015 at 11:41 AM, Antonio Scuri <
>>>>> sc...@tecgraf.puc-rio.br> wrote:
>>>>>
>>>>>>  Try this:
>>>>>>
>>>>>> int iuplua_isihandle(lua_State *L, int pos)
>>>>>> {
>>>>>>   lua_getmetatable(L, pos);   /* t2 = metatable(stack(pos)) */
>>>>>>   lua_pushstring(L, "iupHandle");
>>>>>>   lua_gettable(L, LUA_REGISTRYINDEX);  /* t = registry["iupHandle"] */
>>>>>>   if (lua_rawequal(L, -2, -1))   /* check (t2==t)? */
>>>>>>   {
>>>>>>     lua_pop(L, 2);
>>>>>>     return 1;
>>>>>>   }
>>>>>>   else
>>>>>>     return 0;
>>>>>> }
>>>>>>
>>>>>>   Just commit to the SVN.
>>>>>>
>>>>>> Best,
>>>>>> Scuri
>>>>>>
>>>>>>
>>>>>> On Fri, Jul 10, 2015 at 12:57 PM, Milind Gupta <
>>>>>> milind.gu...@gmail.com> wrote:
>>>>>>
>>>>>>> Hi,
>>>>>>>          I wanted to pass a ihandle to C but I don't want it to
>>>>>>> throw an error if it is not a ihandle but return nil and a error 
>>>>>>> message.
>>>>>>> How can I do that? Do I have to use the lua_touserdata function? How 
>>>>>>> can I
>>>>>>> then check whether I have received a ihandle without throwing an error?
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Milind
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> ------------------------------------------------------------------------------
>>>>>>> Don't Limit Your Business. Reach for the Cloud.
>>>>>>> GigeNET's Cloud Solutions provide you with the tools and support that
>>>>>>> you need to offload your IT needs and focus on growing your business.
>>>>>>> Configured For All Businesses. Start Your Cloud Today.
>>>>>>> https://www.gigenetcloud.com/
>>>>>>> _______________________________________________
>>>>>>> Iup-users mailing list
>>>>>>> Iup-users@lists.sourceforge.net
>>>>>>> https://lists.sourceforge.net/lists/listinfo/iup-users
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>> ------------------------------------------------------------------------------
>>>>>> Don't Limit Your Business. Reach for the Cloud.
>>>>>> GigeNET's Cloud Solutions provide you with the tools and support that
>>>>>> you need to offload your IT needs and focus on growing your business.
>>>>>> Configured For All Businesses. Start Your Cloud Today.
>>>>>> https://www.gigenetcloud.com/
>>>>>> _______________________________________________
>>>>>> Iup-users mailing list
>>>>>> Iup-users@lists.sourceforge.net
>>>>>> https://lists.sourceforge.net/lists/listinfo/iup-users
>>>>>>
>>>>>>
>>>>>
>>>>
>>>>
>>>> ------------------------------------------------------------------------------
>>>> Don't Limit Your Business. Reach for the Cloud.
>>>> GigeNET's Cloud Solutions provide you with the tools and support that
>>>> you need to offload your IT needs and focus on growing your business.
>>>> Configured For All Businesses. Start Your Cloud Today.
>>>> https://www.gigenetcloud.com/
>>>> _______________________________________________
>>>> Iup-users mailing list
>>>> Iup-users@lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/iup-users
>>>>
>>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Don't Limit Your Business. Reach for the Cloud.
>>> GigeNET's Cloud Solutions provide you with the tools and support that
>>> you need to offload your IT needs and focus on growing your business.
>>> Configured For All Businesses. Start Your Cloud Today.
>>> https://www.gigenetcloud.com/
>>> _______________________________________________
>>> Iup-users mailing list
>>> Iup-users@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/iup-users
>>>
>>>
>>
>
>
> ------------------------------------------------------------------------------
> Don't Limit Your Business. Reach for the Cloud.
> GigeNET's Cloud Solutions provide you with the tools and support that
> you need to offload your IT needs and focus on growing your business.
> Configured For All Businesses. Start Your Cloud Today.
> https://www.gigenetcloud.com/
> _______________________________________________
> Iup-users mailing list
> Iup-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/iup-users
>
>
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Iup-users mailing list
Iup-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/iup-users

Reply via email to