Lua-cURL / Lua-cURLv3

Lua binding to libcurl
MIT License
275 stars 63 forks source link

Expose type of userdata and tables through metatables __type #168

Closed cryi closed 3 years ago

cryi commented 3 years ago

Hi,

I wonder whether you would accept exposing tzpe of userdatas and tables through __type in metatables. It is easier to determine real userdata/table type this way than using tostring. Of course I can add it and make pull requested. For now just want to know whether you would accept such change.

I work right now into integrating lua-cURLv3 more closely into eli@0.13.0 and providing simple RestClient implementation based on it. Raw lua-cURLv3 is available for other scenarios that this client won't cover. I can inject __type into all your metatables on my side of course, but it feels more reasonable to do it on your side and making it generally available feature.

moteus commented 3 years ago

Seems reasonable idea. Although, this meta field is not standard. But library has 2 layers. First one is a C part and it has its own metatable. Lua wrapper has separate set of libraries

cryi commented 3 years ago

Yes I know this is not standard, but I would say it is quite common to do this to create custom types. E.g. jirutka/mtype.

2 layers are not an issue here. Can do this on both or on one of them whatever you think suits your project best. So what do you think? Would this be acceptable PR for you?

moteus commented 3 years ago

I belive that the _type field should be added to all metatables

cryi commented 3 years ago

OK I will look into that. Although not sure when.

cryi commented 3 years ago

Hi @moteus please check #173. It should be ready for merge.