File: ternary.h

package info (click to toggle)
python-pyglm 2.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,008 kB
  • sloc: cpp: 53,029; python: 3,683; makefile: 7
file content (22 lines) | stat: -rw-r--r-- 522 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#pragma once

#include "../../compiler_setup.h"
#include "../../internal_functions/all.h"

PyDoc_STRVAR(ternary_if_else_docstr,
	"if_else(b, x, y) -> Any\n"
	"	Equivalent to `x if b else y`."
);
static PyObject*
ternary_if_else(PyObject*, PyObject* args) {
	PyObject* b, * x, * y;
	PyGLM_Arg_Unpack_3O(args, "if_else", b, x, y);

	if (PyObject_IsTrue(b)) {
		return PyGLM_INCREF(x);
	}
	return PyGLM_INCREF(y);
}

#define TERNARY_METHODS \
{ "if_else", (PyCFunction)ternary_if_else, METH_VARARGS, ternary_if_else_docstr }