本文整理匯總了Golang中C.int函數的典型用法代碼示例。如果您正苦於以下問題:Golang int函數的具體用法?Golang int怎麽用?Golang int使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了int函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewField
func NewField(height int, width int, top int, left int, offscreen int, nbuf int) (*Field, error) {
field := (*Field)(C.new_field(C.int(height), C.int(width), C.int(top), C.int(left), C.int(offscreen), C.int(nbuf)))
if field == nil {
return nil, FormsError{"NewField failed"}
}
return field, nil
}
示例2: Prepare
// Prepare query string. Return a new statement.
func (c *SQLiteConn) Prepare(query string) (driver.Stmt, error) {
pquery := C.CString(query)
defer C.free(unsafe.Pointer(pquery))
var s *C.sqlite3_stmt
var tail *C.char
rv := C.sqlite3_prepare_v2(c.db, pquery, -1, &s, &tail)
if rv != C.SQLITE_OK {
return nil, c.lastError()
}
var t string
if tail != nil && *tail != '\000' {
t = strings.TrimSpace(C.GoString(tail))
}
nv := int(C.sqlite3_bind_parameter_count(s))
var nn []string
for i := 0; i < nv; i++ {
pn := C.GoString(C.sqlite3_bind_parameter_name(s, C.int(i+1)))
if len(pn) > 1 && pn[0] == '$' && 48 <= pn[1] && pn[1] <= 57 {
nn = append(nn, C.GoString(C.sqlite3_bind_parameter_name(s, C.int(i+1))))
}
}
ss := &SQLiteStmt{c: c, s: s, nv: nv, nn: nn, t: t}
runtime.SetFinalizer(ss, (*SQLiteStmt).Close)
return ss, nil
}
示例3: getDecode
func (c *Code) getDecode(errList []byte, cache bool) (node *decodeNode) {
if cache {
node = c.decode.getDecode(errList, 0, byte(c.M))
} else {
node = newDecodeNode(errList, byte(c.M))
}
node.mutex.Lock()
defer node.mutex.Unlock()
if node.galoisTables == nil || node.decodeIndex == nil {
node.galoisTables = make([]byte, c.K*c.M*32)
node.decodeIndex = make([]byte, c.K)
decodeMatrix := make([]byte, c.M*c.K)
srcInErr := make([]byte, c.M)
nErrs := len(errList)
nSrcErrs := 0
for _, err := range errList {
srcInErr[err] = 1
if int(err) < c.K {
nSrcErrs++
}
}
C.gf_gen_decode_matrix((*C.uchar)(&c.EncodeMatrix[0]), (*C.uchar)(&decodeMatrix[0]), (*C.uchar)(&node.decodeIndex[0]), (*C.uchar)(&errList[0]), (*C.uchar)(&srcInErr[0]), C.int(nErrs), C.int(nSrcErrs), C.int(c.K), C.int(c.M))
C.ec_init_tables(C.int(c.K), C.int(nErrs), (*C.uchar)(&decodeMatrix[0]), (*C.uchar)(&node.galoisTables[0]))
}
return node
}
示例4: Sethook
// Sets the debugging hook function.
//
// Argument fn is the hook function. mask specifies on which events the hook
// will be called: it is formed by a bitwise OR of the constants Maskcall,
// Maskret, Maskline, and Maskcount. The count argument is only meaningful
// when the mask includes Maskcount. The hook is called for each event type
// present in mask.
//
// A hook is disabled by setting mask to 0.
func (s *State) Sethook(fn Hook, mask, count int) error {
s.Getglobal(namehooks)
if mask&Maskcall == Maskcall {
s.Pushstring(namecall)
s.Pushlightuserdata(unsafe.Pointer(&fn))
s.Settable(-3)
}
if mask&Maskret == Maskret {
s.Pushstring(nameret)
s.Pushlightuserdata(unsafe.Pointer(&fn))
s.Settable(-3)
}
if mask&Maskline == Maskline {
s.Pushstring(nameline)
s.Pushlightuserdata(unsafe.Pointer(&fn))
s.Settable(-3)
}
if mask&Maskcount == Maskcount {
s.Pushstring(namecount)
s.Pushlightuserdata(unsafe.Pointer(&fn))
s.Settable(-3)
}
s.Pop(1) // pop hook table
C.sethook(s.l, C.int(mask), C.int(count))
return nil
}
示例5: RecoverPubkey
//recovers the public key from the signature
//recovery of pubkey means correct signature
func RecoverPubkey(msg []byte, sig []byte) []byte {
if len(sig) != 65 {
log.Panic()
}
var pubkey []byte = make([]byte, 33)
var msg_ptr *C.uchar = (*C.uchar)(unsafe.Pointer(&msg[0]))
var sig_ptr *C.uchar = (*C.uchar)(unsafe.Pointer(&sig[0]))
var pubkey_ptr *C.uchar = (*C.uchar)(unsafe.Pointer(&pubkey[0]))
var pubkeylen C.int
ret := C.secp256k1_ecdsa_recover_compact(
msg_ptr, C.int(len(msg)),
sig_ptr,
pubkey_ptr, &pubkeylen,
C.int(1), C.int(sig[64]),
)
if ret == 0 || int(pubkeylen) != 33 {
return nil
}
return pubkey
}
示例6: NewMat
func NewMat(r, c int) Mat {
var m Mat
m.mat = C.NewGOMat(C.int(r), C.int(c))
//m.Row() = r
//m.Colunm() = c
return m
}
示例7: Play
func (t *Sound) Play(loops int) {
t.channel = int(C.Mix_PlayChannelTimed(C.int(-1), t.chunk, C.int(loops), C.int(-1)))
if t.channel == -1 {
panic(fmt.Sprintf("Unable to play Sound file (%v): %v", t.name, util.GetMixError()))
}
t.SetVolume(GDefaultVolume)
}
示例8: Update
// MONGO_EXPORT int mongo_update( mongo *conn, const char *ns, const bson *cond,
// const bson *op, int flags, mongo_write_concern *custom_write_concern );
func (m *Mongo) Update(ns string, cond, op *Bson, flags int, writeConcern *MongoWriteConcern) int {
if writeConcern == nil {
return int(C.mongo_update(m.conn, C.CString(ns), cond._bson, op._bson, C.int(flags), nil))
}
return int(C.mongo_update(m.conn, C.CString(ns), cond._bson,
op._bson, C.int(flags), writeConcern.writeConcern))
}
示例9: find
func (re *Regexp) find(b []byte, n int, offset int) (match []int) {
if n == 0 {
b = []byte{0}
}
ptr := unsafe.Pointer(&b[0])
matchData := re.matchData
capturesPtr := unsafe.Pointer(&(matchData.indexes[matchData.count][0]))
numCaptures := int32(0)
numCapturesPtr := unsafe.Pointer(&numCaptures)
pos := int(C.SearchOnigRegex((ptr), C.int(n), C.int(offset), C.int(ONIG_OPTION_DEFAULT), re.regex, re.region, re.errorInfo, (*C.char)(nil), (*C.int)(capturesPtr), (*C.int)(numCapturesPtr)))
if pos >= 0 {
if numCaptures <= 0 {
panic("cannot have 0 captures when processing a match")
}
match2 := matchData.indexes[matchData.count][:numCaptures*2]
match = make([]int, len(match2))
for i := range match2 {
match[i] = int(match2[i])
}
numCapturesInPattern := int32(C.onig_number_of_captures(re.regex)) + 1
if numCapturesInPattern != numCaptures {
log.Fatalf("expected %d captures but got %d\n", numCapturesInPattern, numCaptures)
}
}
return
}
示例10: Parse
func Parse(content, inEncoding, url []byte, options int, outEncoding []byte) (doc *XmlDocument, err error) {
inEncoding = AppendCStringTerminator(inEncoding)
outEncoding = AppendCStringTerminator(outEncoding)
var docPtr *C.xmlDoc
contentLen := len(content)
if contentLen > 0 {
var contentPtr, urlPtr, encodingPtr unsafe.Pointer
contentPtr = unsafe.Pointer(&content[0])
if len(url) > 0 {
url = AppendCStringTerminator(url)
urlPtr = unsafe.Pointer(&url[0])
}
if len(inEncoding) > 0 {
encodingPtr = unsafe.Pointer(&inEncoding[0])
}
docPtr = C.xmlParse(contentPtr, C.int(contentLen), urlPtr, encodingPtr, C.int(options), nil, 0)
if docPtr == nil {
err = ERR_FAILED_TO_PARSE_XML
} else {
doc = NewDocument(unsafe.Pointer(docPtr), contentLen, inEncoding, outEncoding)
}
} else {
doc = CreateEmptyDocument(inEncoding, outEncoding)
}
return
}
示例11: Emit
// Emit is a wrapper around g_signal_emitv() and emits the signal
// specified by the string s to an Object. Arguments to callback
// functions connected to this signal must be specified in args. Emit()
// returns an interface{} which must be type asserted as the Go
// equivalent type to the return value for native C callback.
//
// Note that this code is unsafe in that the types of values in args are
// not checked against whether they are suitable for the callback.
func (v *Object) Emit(s string, args ...interface{}) (interface{}, error) {
cstr := C.CString(s)
defer C.free(unsafe.Pointer(cstr))
// Create array of this instance and arguments
valv := C.alloc_gvalue_list(C.int(len(args)) + 1)
defer C.free(unsafe.Pointer(valv))
// Add args and valv
val, err := GValue(v)
if err != nil {
return nil, errors.New("Error converting Object to GValue: " + err.Error())
}
C.val_list_insert(valv, C.int(0), val.native())
for i := range args {
val, err := GValue(args[i])
if err != nil {
return nil, fmt.Errorf("Error converting arg %d to GValue: %s", i, err.Error())
}
C.val_list_insert(valv, C.int(i+1), val.native())
}
t := v.TypeFromInstance()
// TODO: use just the signal name
id := C.g_signal_lookup((*C.gchar)(cstr), C.GType(t))
ret, err := ValueAlloc()
if err != nil {
return nil, errors.New("Error creating Value for return value")
}
C.g_signal_emitv(valv, id, C.GQuark(0), ret.native())
return ret.GoValue()
}
示例12: Setupvalue
// Sets the value of a closure's upvalue. It assigns the value at the top
// of the stack to the upvalue and returns its name. It also pops the value
// from the stack. Parameters funcindex and n are as in the Getupvalue.
//
// Returns an error (and pops nothing) when the index is greater
// than the number of upvalues.
func (this *State) Setupvalue(funcindex, n int) (string, error) {
r := C.lua_setupvalue(this.luastate, C.int(funcindex), C.int(n))
if r == nil {
return "", errors.New("index exceeds number of upvalues")
}
return C.GoString(r), nil
}
示例13: Link
func (field *Field) Link(top int, left int) (*Field, error) {
link := (*Field)(C.link_field((*C.FIELD)(field), C.int(top), C.int(left)))
if link == nil {
return nil, FormsError{"Field.Link failed"}
}
return link, nil
}
示例14: DupField
func (field *Field) DupField(top int, left int) (*Field, error) {
dup := (*Field)(C.dup_field((*C.FIELD)(field), C.int(top), C.int(left)))
if dup == nil {
return nil, FormsError{"Field.Dup failed"}
}
return dup, nil
}
示例15: _CGO
// The C side of things will still need to allocate memory, due to the slices.
// Assumes Configuration is valid.
func (config *Configuration) _CGO() *C.CGO_Configuration {
INFO.Println("Converting Config: ", config)
size := C.size_t(unsafe.Sizeof(C.CGO_Configuration{}))
c := (*C.CGO_Configuration)(C.malloc(size))
// Need to convert each IceServer struct individually.
total := len(config.IceServers)
if total > 0 {
sizeof := unsafe.Sizeof(C.CGO_IceServer{})
cServers := unsafe.Pointer(C.malloc(C.size_t(sizeof * uintptr(total))))
ptr := uintptr(cServers)
for _, server := range config.IceServers {
*(*C.CGO_IceServer)(unsafe.Pointer(ptr)) = server._CGO()
ptr += sizeof
}
c.iceServers = (*C.CGO_IceServer)(cServers)
}
c.numIceServers = C.int(total)
// c.iceServers = (*C.CGO_IceServer)(unsafe.Pointer(&config.IceServers))
c.iceTransportPolicy = C.int(config.IceTransportPolicy)
c.bundlePolicy = C.int(config.BundlePolicy)
// [ED] c.RtcpMuxPolicy = C.int(config.RtcpMuxPolicy)
c.peerIdentity = C.CString(config.PeerIdentity)
// [ED] c.Certificates = config.Certificates
// [ED] c.IceCandidatePoolSize = C.int(config.IceCandidatePoolSize)
return c
}