protected function wrapScalar($var, $name)
    {
        self::checkVariableName($name);

        if (is_object($var)) {
            if ($var instanceof \Erebot\Styling\VariableInterface) {
                return $var;
            }

            if (!is_callable(array($var, '__toString'), false)) {
                throw new \InvalidArgumentException(
                    $name.' must be a scalar or an instance of '.
                    '\\Erebot\\Styling\\VariableInterface'
                );
            }
        }

        if (is_array($var)) {
            return $var;
        }

        if (is_string($var) || is_callable(array($var, '__toString'), false)) {
            $cls = $this->cls['string'];
        } elseif (is_int($var)) {
            $cls = $this->cls['int'];
        } elseif (is_float($var)) {
            $cls = $this->cls['float'];
        } else {
            throw new \InvalidArgumentException(
                'Unsupported scalar type ('.gettype($var).') for "'.$name.'"'
            );
        }
        return new $cls($var);
    }