-
Notifications
You must be signed in to change notification settings - Fork 9
/
long.go
50 lines (40 loc) · 1 KB
/
long.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2011 Julian Phillips. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package py
// #include "utils.h"
// static inline long longCheck(PyObject *o) { return PyLong_Check(o); }
import "C"
import (
"fmt"
"unsafe"
)
type Long struct {
AbstractObject
NumberProtocol
o C.PyLongObject
}
// LongType is the Type object that represents the Long type.
var LongType = (*Type)(unsafe.Pointer(C.getBasePyType(C.GoPyLong_Type)))
func longCheck(obj Object) bool {
if obj == nil {
return false
}
return C.longCheck(c(obj)) != 0
}
func newLong(obj *C.PyObject) *Long {
return (*Long)(unsafe.Pointer(obj))
}
func NewLong(i int64) *Long {
return newLong(C.PyLong_FromLongLong(C.PY_LONG_LONG(i)))
}
func (l *Long) Int64() int64 {
// TODO: AsLongLong doesn't work for me on windows...
return int64(C.PyLong_AsLong(c(l)))
}
func (l *Long) String() string {
if l == nil {
return "<nil>"
}
return fmt.Sprintf("%v", l.Int64())
}