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_newtable(L); /* create metatable */
lua_pushvalue(L, -1); /* duplicate metatable to set*/ 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); lua_rawsetp(L, LUA_REGISTRYINDEX, p);
return 1; 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_pushliteral (L, "__index"); /* define metamethods */
lua_pushvalue (L, -2); lua_pushvalue (L, -2);
lua_settable (L, -3); lua_settable (L, -3);
return 1; return 1;
} }

View File

@ -219,8 +219,9 @@ local function form_add(form, data)
return form return form
end end
local function class(ctor) local function class(ctor, type_name)
local C = {} local C = {}
C.__type = type_name or "LcURL Unknown"
C.__index = function(self, k) C.__index = function(self, k)
local fn = C[k] local fn = C[k]
@ -254,7 +255,7 @@ end
local function Load_cURLv2(cURL, curl) 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 perform = wrap_function("perform")
local setopt_share = wrap_function("setopt_share") 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 perform = wrap_function("perform")
local add_handle = wrap_function("add_handle") 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", { Share.setopt_share = wrap_setopt_flags("share", {
[ "COOKIE" ] = curl.LOCK_DATA_COOKIE; [ "COOKIE" ] = curl.LOCK_DATA_COOKIE;
@ -485,7 +486,7 @@ end
local function Load_cURLv3(cURL, curl) local function Load_cURLv3(cURL, curl)
------------------------------------------- -------------------------------------------
local Form = class(curl.form) do local Form = class(curl.form, "LcURL Form") do
function Form:__init(opt) function Form:__init(opt)
if opt then return self:add(opt) end 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) function Easy:__init(opt)
if opt then return self:setopt(opt) end 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 add_handle = wrap_function("add_handle")
local remove_handle = wrap_function("remove_handle") local remove_handle = wrap_function("remove_handle")