Merge pull request #173 from cryi/master

Added type names for exposed metatables
This commit is contained in:
Alexey Melnichuk 2021-05-01 15:57:32 +03:00 committed by GitHub
commit 9f8b6dba8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 8 deletions

View File

@ -68,6 +68,11 @@ int lutil_newmetatablep (lua_State *L, const void *p) {
lua_newtable(L); /* create metatable */
lua_pushvalue(L, -1); /* duplicate metatable to set*/
lua_pushliteral (L, "__type");
lua_pushstring(L, p); // push meta name
lua_settable (L, -3); // set meta name
lua_rawsetp(L, LUA_REGISTRYINDEX, p);
return 1;
@ -122,7 +127,6 @@ int lutil_createmetap (lua_State *L, const void *p, const luaL_Reg *methods, int
lua_pushliteral (L, "__index"); /* define metamethods */
lua_pushvalue (L, -2);
lua_settable (L, -3);
return 1;
}

View File

@ -219,8 +219,9 @@ local function form_add(form, data)
return form
end
local function class(ctor)
local function class(ctor, type_name)
local C = {}
C.__type = type_name or "LcURL Unknown"
C.__index = function(self, k)
local fn = C[k]
@ -254,7 +255,7 @@ end
local function Load_cURLv2(cURL, curl)
-------------------------------------------
local Easy = class(curl.easy) do
local Easy = class(curl.easy, "LcURL Easy") do
local perform = wrap_function("perform")
local setopt_share = wrap_function("setopt_share")
@ -400,7 +401,7 @@ end
-------------------------------------------
-------------------------------------------
local Multi = class(curl.multi) do
local Multi = class(curl.multi, "LcURL Multi") do
local perform = wrap_function("perform")
local add_handle = wrap_function("add_handle")
@ -460,7 +461,7 @@ end
-------------------------------------------
-------------------------------------------
local Share = class(curl.share) do
local Share = class(curl.share, "LcURL Share") do
Share.setopt_share = wrap_setopt_flags("share", {
[ "COOKIE" ] = curl.LOCK_DATA_COOKIE;
@ -485,7 +486,7 @@ end
local function Load_cURLv3(cURL, curl)
-------------------------------------------
local Form = class(curl.form) do
local Form = class(curl.form, "LcURL Form") do
function Form:__init(opt)
if opt then return self:add(opt) end
@ -505,7 +506,7 @@ end
-------------------------------------------
-------------------------------------------
local Easy = class(curl.easy) do
local Easy = class(curl.easy, "LcURL Easy") do
function Easy:__init(opt)
if opt then return self:setopt(opt) end
@ -595,7 +596,7 @@ end
-------------------------------------------
-------------------------------------------
local Multi = class(curl.multi) do
local Multi = class(curl.multi, "LcURL Multi") do
local add_handle = wrap_function("add_handle")
local remove_handle = wrap_function("remove_handle")