Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

10 440 Posts in 5 815 Topics- by 1 216 Members - Latest Member: santini862

15 October 2019, 21:16
Select Language English | Russian ru | German
Main PageIRC Client KVIrc forumRussian talksСкриптингГотовые скриптыСкриптеру в помощь: var_dump
Pages: [1]
Print
Author Topic: Скриптеру в помощь: var_dump  (Read 12014 times)
0 Members and 1 Guest are viewing this topic.
Maximusya
Глобальный модератор
*****

Репутация: 49
Gender: Male
Posts: 343



View Profile
« on: 31 May 2009, 00:31 »

Вот, чего мне не хватало!
Сделал вывод похожим на php-шный. Конечно же, поддерживает вложенные структуры данных. Пока что не работает с объектами. Ну и вообще, нужно разнообразное тестирование. Для моих "повседневных" целей отлично подошел)
Импортируются алиасы:
var_dump : $var_dump(%var)
str_repeat : %line = $str_repeat("-", 7)

Code:
alias(str_repeat)
{
/*
Returns repeated streing
$0 - string to repeat
$1 - times to repeat
*/
%mult = $int($1);
for (%i=0; %i<%mult; %i++)
%res .= $0;
return %res;
}


alias(var_dump)
{
%type = $typeof($0)
%var = $0;
%indent = $int($1);
%indent_char = $string($2);
if ($str.len(%indent_char) == 0)
%indent_char = "   "

switch(%type)
{
case(string)
{
echo $str_repeat(%indent_char, %indent)string($length($0)) \"$0\";
break;
}
case(integer)
{
echo $str_repeat(%indent_char, %indent)integer($0);
break
}
case(real)
{
echo $str_repeat(%indent_char, %indent)real($0);
break
}
case(boolean)
{
echo $str_repeat(%indent_char, %indent)boolean($0);
break
}
case(array)
{
echo $str_repeat(%indent_char, %indent)array($length($0)) \{;
for(%i=0;%i<$length($0);%i++)
{
echo $str_repeat(%indent_char, $(%indent+1))\[%i] =>
$var_dump($0[%i], $(%indent+1), %indent_char);
}
echo $str_repeat(%indent_char, %indent)\};
break;
}
case(hash)
{
echo $str_repeat(%indent_char, %indent)hash($length($0)) \{;
foreach(%i, $keys($0))
{
echo $str_repeat(%indent_char, $(%indent+1))\[%i] =>
$var_dump($0{%i}, $(%indent+1), %indent_char);
}
echo $str_repeat(%indent_char, %indent)\};
break;
}
case(hobject)
{
if ($isSet($0))
echo $str_repeat(%indent_char, %indent)hobject($0->$className()) $0->$name() \{
else
echo $str_repeat(%indent_char, %indent)hobject(null-object) \{
if ($objects.exists($0))
{
%vars_hash = $objects.variables($0);
//$var_dump(%vars_hash, $(%indent+1), %indent_char)
if ($isSet(%vars_hash))
{
foreach(%i, $keys(%vars_hash))
{
echo $str_repeat(%indent_char, $(%indent+1))\[%i] =>
$var_dump(%vars_hash{%i}, $(%indent+1), %indent_char);
}
}
}
else
{
$var_dump($nothing, $(%indent+1), %indent_char);
}
echo $str_repeat(%indent_char, %indent)\};
break;
}
case(nothing)
{
echo $str_repeat(%indent_char, %indent)nothing
break;
}
default
{
echo $str_repeat(%indent_char, %indent)%type(Not implemented) \{
echo $str_repeat(%indent_char, $(%indent+1))$0
echo $str_repeat(%indent_char, %indent)\};
break;
}
}
}

Например
/$var_dump($array(hello, $int(4), $hash(5, $real(6.4), hell, $false)))

Code:
[23:26:52] array(3) {
[23:26:52]    [0] =>
[23:26:52]    string(5) "hello"
[23:26:52]    [1] =>
[23:26:52]    integer(4)
[23:26:52]    [2] =>
[23:26:52]    hash(2) {
[23:26:52]       [5] =>
[23:26:52]       real(6.400000)
[23:26:52]       [hell] =>
[23:26:52]       boolean(0)
[23:26:52]    }
[23:26:52] }
« Last Edit: 31 May 2009, 15:19 by Maximusya » Logged
Maximusya
Глобальный модератор
*****

Репутация: 49
Gender: Male
Posts: 343



View Profile
« Reply #1 on: 31 May 2009, 11:47 »

Оказалось, объекты $null обрабатываются по-особому.
Добавил обработку произвольного неизвестного типа с попыткой просто сделать echo его содержимого. Ну и пометкой Not implemented
Первый пост обновлен
Logged
Maximusya
Глобальный модератор
*****

Репутация: 49
Gender: Male
Posts: 343



View Profile
« Reply #2 on: 31 May 2009, 15:13 »

Теперь дампятся и объекты. И правильно обрабатываются $nothing и $null значения.
Первый пост обновлен
Logged
Maximusya
Глобальный модератор
*****

Репутация: 49
Gender: Male
Posts: 343



View Profile
« Reply #3 on: 31 May 2009, 15:20 »

В вывод объектов добавлено их имя (если оно им было присвоено)
Первый пост обновлен
Logged
s145
Новичок
*

Репутация: 1
Posts: 13


View Profile
« Reply #4 on: 22 July 2009, 00:16 »

спасибо, правда не знаю еще как я его буду использовать Smiley
Logged
ninest123
Ветеран
*****

Репутация: 0
Posts: 1 382


View Profile Email
« Reply #5 on: 8 August 2018, 12:51 »

chanyuan2018.08.08
canada goose outlet
hornets jerseys
nike factory outlet
prada shoes
bally shoes
mcm outlet
cheap snapbacks
air huarache
true religion outlet
nike pegasus
air jordan 12
birkenstock sandals
raptors jerseys
christian louboutin outlet
tory burch outlet
cheap jordans
nfl jerseys wholesale
tods outlet
supra shoes
air max 1
ferragamo outlet
air force 1
coach outlet
cheap jordans
visvim shoes
san antonio spurs jerseys
trailblazers jerseys
jordan shoes
burberry outlet
longchamp handbags
ferragamo outlet
basketball shoes
michael kors outlet
kevin durant shoes
kappa clothing
canada goose outlet
canada goose outlet
mbt shoes
valentino outlet
nike shoes
pandora charms sale clearance
champion clothing
nike blazer pas cher
cheap jordans
fitflops sale
longchamp solde
ugg boots
ray ban sunglasses
ugg outlet
michael kors outlet
reebok outlet store
coach outlet
mont blanc pens
nike outlet
longchamp bags
kd 10 elite
ugg outlet
ugg boots clearance
pandora charms
merrell shoes
polo ralph lauren
fitflops sale clearance
nhl jerseys
nets jerseys
moncler outlet
ray ban sunglasses
nobis outlet
canada goose outlet
michael kors
adidas outlet
golden goose sneakers
canada goose coats
thunder jerseys
michael kors outlet
pelicans jerseys
true religion jeans
van cleef & arpels jewelry
uggs outlet
dior outlet
coach outlet
palladium boots
herve leger outlet
michael kors outlet
true religion jeans
hermes birkin
chloe sunglassess
freshjive clothing
basketball jerseys
polo outlet
canada goose outlet
rockets jerseys
karen millen dresses
marc jacobs outlet
chopard jewelry
canada goose outlet
coach outlet
coach outlet
ugg outlet
michael kors
brequet wathes
oakley sunglasses
coach outlet store online
grizzlies jerseys
ray ban sunglasses
jerseys from china
oakley sunglasses
moncler outlet
michael kors outlet
canada goose outlet
fingerlings monkey
pandora charms
jimmy choo sunglasses
oakley sunglasses
cheap football shirts
malone souliers mules
76ers jerseys
lakers jerseys
gucci outlet
nike revolution
adidas ultra boost
calvin klein jeans
air jordan release dates
christian louboutin shoes
burberry outlet
polo ralph lauren
cheap mlb jerseys
moncler outlet
tag heuer watches
red bottom shoes
michael kors outlet
swarovski crystal
nfl jersey wholesale
jordan shoes
gucci outlet
mishka clothing
bucks jerseys
ugg boots
michael kors outlet
longchamp outlet
football shirts
dolce and gabbana
ugg outlet
coach outlet online
dsquared2 jeans
true religion jeans
michael kors outlet
audemars piguet watches
canada goose outlet
saucony shoes
canada goose outlet
adidas outlet
longchamp solde
pandora charms
longchamp handbags
off white
fred perry polo shirts
ferragamo outlet
christian louboutin boutique
cazal sunglasses
mulberry handbags
huf clothing
canada goose outlet
cartier jewelry
bulgari jewelry
balmain jeans
true religion jeans
guess factory
cheap jordans
golden state warriors jerseys
michael kors outlet
pandora charms
adidas nmd
canada goose jackets
keen shoes
coach handbags
light up shoes
coach canada
harry winston jewelry
oakley sunglasses
diesel jeans
north face jackets
swarovski outlet
mulberry handbags
uggs outlet
jordan shoes
michael kors outlet online
balenciaga sneakers
ugg boots clearance
under armour outlet
uggs
air jordan shoes
fitflops sale
air jordan shoes
canada goose jackets
michael kors outlet
ray ban sunglasses
tory burch outlet
jordan shoes
jimmy choo shoes
wizards jerseys
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic