Jump to content

Digest January-March

We talk about what was done and updated in the past month. We help keep abreast of events.

March February January

Servers monitoring and the Addons Editor

We present you two legends. All dreams come true.

Servers monitoring The Addons Editor

A statistics bot for Telegram

Convenient analytics right on your phone.

Read more

Game tooltips

Tooltips provide a way for 3rd party fansites and extensions to display detailed information on mouseover.

Read more

The Addons Updater

Let us to introduce the addons updating software and to share the details

Read more Download

Немного о UserMods


Recommended Posts

Разрабы предоставили нам UserMods.* с несколькими функциями. Разберемся, как это работает.

Вот пример:

local userMuds = {}
local debugCowmon = {}

function debugCowmon.ToWs(astr)
return "WSTR_"..astr
end

function userMuds.TestFunc()
return "test"
end

local meta = {}
function meta.__index(op, key)
if key == "ToWString" then
return debugCowmon.ToWs
end
return nil
end
setmetatable(userMuds, meta)

Вызов:

LogInfo(userMuds.TestFunc()) --вызов в обход __index
LogInfo(userMuds.ToWString("testAstring")) --вызов с __index
LogInfo(userMuds.OpenURL("http:\\ya.ru")) --ошибка скрипта (обращние к нулю)

Что тут происходит? Для начала мы создаем 2 новые переменные, представим, что это категории UserMods (нам доступен) и debugCommon (нам недоступен). Как же разарбы дают нам доступ к "своим" функциям?

Если для common.* определены все ключи функций, то для UserMods определена только __index. Далее, если бы ключ при вызове функции был найден (в данном примере это UserMods.TestFunc()), она вызвалась бы в обход __index, но в нашем случае вызывается __index (которая должна возвратить адес функции по ключу), и в ней происходит переопределение userMods.ToWString --> debugCommon.ToWs().

Сори, если не ясно. Писал на сонную голову, завтра поправлю.

Link to comment
Share on other sites

ничего не поняла.. ты скажи можно вызвать функции к которым доступ закрыт? )))

народ писал что есть много функций которые в АПИ неописаны вообще

Link to comment
Share on other sites

  • 5 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using our site you agree to the Terms of Use