Exemplo n.º 1
0
def pack_args(val):
    """
    Convert args for a Q-lua function

    Parameters:
        val: a python object (list, dict, number, string etc)

    Returns:
        a lua representation for given python object
    """

    if is_p_vector(val):
        return val.get_base_vec()
    elif is_p_scalar(val):
        return val.get_base_scalar()
    elif type(val) == list or type(val) == tuple:
        new_list = []
        for arg in val:
            new_list.append(pack_args(arg))
        return to_table(new_list)
    elif type(val) == dict:
        for i, v in val.items():
            val[i] = pack_args(v)
        return to_table(val)
    else:
        return val
Exemplo n.º 2
0
    def __div__(self, other):
        """divide scalar with given value"""

        if is_p_vector(other):
            return other / self
        else:
            return self.__check_and_execute(other, "/")
Exemplo n.º 3
0
    def __mul__(self, other):
        """multiply scalar with given value"""

        if is_p_vector(other):
            return other * self
        else:
            return self.__check_and_execute(other, "*")
Exemplo n.º 4
0
    def __sub__(self, other):
        """subtract given value from scalar"""

        if is_p_vector(other):
            return other - self
        else:
            return self.__check_and_execute(other, "-")
Exemplo n.º 5
0
    def __add__(self, other):
        """add scalar with given value"""

        if is_p_vector(other):
            return other + self
        else:
            return self.__check_and_execute(other, "+")
Exemplo n.º 6
0
    def __mul__(self, other):
        """multiply vector with second value (vector, scalar or number) using '*' operator"""

        if not (is_p_vector(other) or is_p_scalar(other)
                or isinstance(other, int) or isinstance(other, float)):
            raise Exception("Second argument type {} is not supported".format(
                type(other)))
        # call wrapper function
        return self.call_lua_op(q_consts.MUL, self, other)
Exemplo n.º 7
0
    def __sub__(self, other):
        """Subtract second value (vector, scalar or number) from vector using '-' operator"""

        if not (is_p_vector(other) or is_p_scalar(other)
                or isinstance(other, int) or isinstance(other, float)):
            raise Exception("Second argument type {} is not supported".format(
                type(other)))
        # call wrapper function
        return self.call_lua_op(q_consts.SUB, self, other)