Модуль ns_defaultkey для AOL Server

Описание модуля приведено в комментарии в коде.


# Copyright 2009, Mobile Business Group
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.

package require json

# простой интерфейс для управления значениями по умолчанию
# проверки аргументов убраны, т.к. это лишний оверхед, а функции вызываются очень часто
# позволяет установить дефолтовые значения сразу для всех пользователей и сессий
proc ns_defaultkey {action args} {
if {$action eq {exists}} {
return [nsv_exists defaultkeys_[lindex $args 0] [lindex $args 1]]
} elseif {$action eq {names}} {
return [nsv_array names defaultkeys_[lindex $args 0]]
} elseif {$action eq {get}} {
if {[nsv_exists defaultkeys_[lindex $args 0] [lindex $args 1]] == 1} {
return [nsv_get defaultkeys_[lindex $args 0] [lindex $args 1]]
}
return
} elseif {$action eq {get_escape}} {
return [::json::string_escape [ns_defaultkey get {*}$args]]
} elseif {$action eq {set}} {
nsv_set defaultkeys_[lindex $args 0] [lindex $args 1] [lindex $args 2]
return [lindex $args 2]
} elseif {$action eq {add}} {
nsv_set defaultkeys_[lindex $args 0] [lindex $args 1] [concat [nsv_set defaultkeys_[lindex $args 0] [lindex $args 1]] [lindex $args 2]]
return [nsv_get defaultkeys_[lindex $args 0] [lindex $args 1]]
} elseif {$action eq {aset}} {
nsv_array set defaultkeys_[lindex $args 0] [lindex $args 1]
} elseif {$action eq {aget}} {
return [nsv_array get defaultkeys_[lindex $args 0]]
}
}

Comments

Popular posts from this blog

Открытый софт для научных расчетов

Счетчики в SQLite

Модем Huawei E1550 в debian