forked from gmp/jni
38 lines
843 B
Go
38 lines
843 B
Go
// +build !android
|
|
|
|
package jni
|
|
|
|
/*
|
|
#include <stdlib.h>
|
|
#include <jni.h>
|
|
#include "gojni.h"
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
"unsafe"
|
|
)
|
|
|
|
// CreateJavaVM creates a new Java VM with the options specified (if any).
|
|
// This should not be called more than once as it can result in an error if
|
|
// a JVM already exists for a given process.
|
|
//
|
|
// This is not implemented on Android and is therefore excluded on that
|
|
// platform by build flags and C.
|
|
func CreateJavaVM(opts ...string) JVM {
|
|
nOptions := len(opts)
|
|
optstrings := make([]*C.char, nOptions)
|
|
for i, _ := range optstrings {
|
|
optstrings[i] = C.CString(opts[i])
|
|
defer C.free(unsafe.Pointer(optstrings[i]))
|
|
}
|
|
var jvm *C.JavaVM
|
|
if nOptions > 0 {
|
|
jvm = C._jni_CreateJavaVM(&optstrings[0], C.int(nOptions))
|
|
} else {
|
|
jvm = C._jni_CreateJavaVM((**C.char)(nil), 0)
|
|
}
|
|
return JVM{ jvm: jvm }
|
|
}
|
|
|