1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-23 05:51:14 +01:00

Lua fixes

This commit is contained in:
Daniil Gentili 2017-07-28 23:20:50 +02:00
parent 3024dc4a15
commit ade8c07a2c
2 changed files with 18 additions and 36 deletions

View File

@ -136,18 +136,7 @@ class APIFactory
} }
try { try {
$deserialized = method_exists($this->API, $this->namespace.$name) ? $this->API->{$this->namespace.$name}(...$arguments) : $this->API->method_call($this->namespace.$name, (isset($arguments[0]) && $this->is_array($arguments[0])) ? $arguments[0] : [], $aargs); $deserialized = method_exists($this->API, $this->namespace.$name) ? $this->API->{$this->namespace.$name}(...$arguments) : $this->API->method_call($this->namespace.$name, (isset($arguments[0]) && $this->is_array($arguments[0])) ? $arguments[0] : [], $aargs);
array_walk_recursive($deserialized, function (&$value, $key) { Lua::convert_objects($deserialized);
if (is_object($value)) {
$newval = [];
foreach (get_class_methods($value) as $key => $name) {
$newval[$key] = [$value, $name];
}
foreach ($value as $key => $name) {
$newval[$key] = $name;
}
$value = $newval;
}
});
return $deserialized; return $deserialized;
} catch (\danog\MadelineProto\Exception $e) { } catch (\danog\MadelineProto\Exception $e) {

View File

@ -84,18 +84,7 @@ class Lua
if (is_callable($cb)) { if (is_callable($cb)) {
$cb($result, $cb_extra); $cb($result, $cb_extra);
} }
array_walk_recursive($result, function (&$value, $key) { self::convert_objects($result);
if (is_object($value)) {
$newval = [];
foreach (get_class_methods($value) as $key => $name) {
$newval[$key] = [$value, $name];
}
foreach ($value as $key => $name) {
$newval[$key] = $name;
}
$value = $newval;
}
});
return $result; return $result;
} }
@ -137,18 +126,7 @@ class Lua
public function __call($name, $params) public function __call($name, $params)
{ {
array_walk_recursive($params, function (&$value, $key) { self::convert_objects($params);
if (is_object($value)) {
$newval = [];
foreach (get_class_methods($value) as $key => $name) {
$newval[$key] = [$value, $name];
}
foreach ($value as $key => $name) {
$newval[$key] = $name;
}
$value = $newval;
}
});
try { try {
return $this->Lua->{$name}(...$params); return $this->Lua->{$name}(...$params);
} catch (\danog\MadelineProto\RPCErrorException $e) { } catch (\danog\MadelineProto\RPCErrorException $e) {
@ -172,4 +150,19 @@ class Lua
{ {
return $this->Lua->{$name} = $value; return $this->Lua->{$name} = $value;
} }
public static function convert_objects(&$data) {
array_walk_recursive($data, function (&$value, $key) {
if (is_object($value)) {
$newval = [];
foreach (get_class_methods($value) as $key => $name) {
$newval[$key] = [$value, $name];
}
foreach ($value as $key => $name) {
$newval[$key] = $name;
}
if ($newval === []) $newval = $value->__toString();
$value = $newval;
}
});
}
} }