Lua fixes

This commit is contained in:
Daniil Gentili 2017-07-27 09:04:46 +02:00
parent 1adf1b4120
commit cac9b280b0
2 changed files with 31 additions and 1 deletions

View File

@ -135,7 +135,20 @@ class APIFactory
return 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);
}
try {
return 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) {
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;
} catch (\danog\MadelineProto\Exception $e) {
return ['error_code' => $e->getCode(), 'error' => $e->getMessage()];
} catch (\danog\MadelineProto\RPCErrorException $e) {

View File

@ -58,6 +58,11 @@ class Lua
}
$this->{$namespace} = $methods[$namespace];
}
$this->MadelineProto->lua = true;
foreach ($this->MadelineProto->get_methods_namespaced() as $method => $namespace) {
$this->MadelineProto->{$namespace}->lua = true;
}
}
public function tdcli_function($params, $cb = null, $cb_extra = null)
@ -133,6 +138,18 @@ class Lua
public function __call($name, $params)
{
array_walk_recursive($params, 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;
}
$value = $newval;
}
});
try {
return $this->Lua->{$name}(...$params);
} catch (\danog\MadelineProto\RPCErrorException $e) {