mirror of https://github.com/liamg/aminal.git
Switchs to go modules
This allows the project to be built out of the GOPATH and is offically built into the go tools.
This commit is contained in:
parent
9ed4f28bc8
commit
c320460ffb
|
@ -1,99 +0,0 @@
|
||||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
|
||||||
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/BurntSushi/toml"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005"
|
|
||||||
version = "v0.3.1"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/davecgh/go-spew"
|
|
||||||
packages = ["spew"]
|
|
||||||
revision = "8991bc29aa16c548c550c7ff78260e27b9ab7c73"
|
|
||||||
version = "v1.1.1"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/go-gl/gl"
|
|
||||||
packages = ["all-core/gl"]
|
|
||||||
revision = "629e6eb0370bc1987d806c0786368395657324a0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/go-gl/glfw"
|
|
||||||
packages = ["v3.2/glfw"]
|
|
||||||
revision = "691ee1b84c51ae625ed1aafebc915d3db3d63d66"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/gobuffalo/packr"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "5a2cbb54c4e7d482e3f518c56f1f86f133d5204f"
|
|
||||||
version = "v1.13.7"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/golang/freetype"
|
|
||||||
packages = [".","raster","truetype"]
|
|
||||||
revision = "e2365dfdc4a05e4b8299a783240d4a7d5a65d4e4"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/kr/pty"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "db8e3cd836b82e82e0a9c8edc6896967dd31374f"
|
|
||||||
version = "v1.1.3"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/pkg/errors"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "645ef00459ed84a119197bfb8d8205042c6df63d"
|
|
||||||
version = "v0.8.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/pmezard/go-difflib"
|
|
||||||
packages = ["difflib"]
|
|
||||||
revision = "792786c7400a136282c1664665ae0a8db921c6c2"
|
|
||||||
version = "v1.0.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/riywo/loginshell"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "5da3acff02554cee5e8ccb4651cc5a4072f41790"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "github.com/stretchr/testify"
|
|
||||||
packages = ["assert","require"]
|
|
||||||
revision = "f35b8ab0b5a2cef36673838d662e249dd9c94686"
|
|
||||||
version = "v1.2.2"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "go.uber.org/atomic"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "1ea20fb1cbb1cc08cbd0d913a96dead89aa18289"
|
|
||||||
version = "v1.3.2"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "go.uber.org/multierr"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "3c4937480c32f4c13a875a1829af76c98ca3d40a"
|
|
||||||
version = "v1.1.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
name = "go.uber.org/zap"
|
|
||||||
packages = [".","buffer","internal/bufferpool","internal/color","internal/exit","zapcore"]
|
|
||||||
revision = "ff33455a0e382e8a81d14dd7c922020b6b5e7982"
|
|
||||||
version = "v1.9.1"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "golang.org/x/image"
|
|
||||||
packages = ["bmp","font","math/fixed"]
|
|
||||||
revision = "991ec62608f3c0da01d400756917825d1e2fd528"
|
|
||||||
|
|
||||||
[solve-meta]
|
|
||||||
analyzer-name = "dep"
|
|
||||||
analyzer-version = 1
|
|
||||||
inputs-digest = "6f1eff05a1c5ca969d1f54eb8002e3213fda92b99a459e6729098b2497de5b8c"
|
|
||||||
solver-name = "gps-cdcl"
|
|
||||||
solver-version = 1
|
|
45
Gopkg.toml
45
Gopkg.toml
|
@ -1,45 +0,0 @@
|
||||||
# Gopkg.toml example
|
|
||||||
#
|
|
||||||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
|
|
||||||
# for detailed Gopkg.toml documentation.
|
|
||||||
#
|
|
||||||
# required = ["github.com/user/thing/cmd/thing"]
|
|
||||||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
|
|
||||||
#
|
|
||||||
# [[constraint]]
|
|
||||||
# name = "github.com/user/project"
|
|
||||||
# version = "1.0.0"
|
|
||||||
#
|
|
||||||
# [[constraint]]
|
|
||||||
# name = "github.com/user/project2"
|
|
||||||
# branch = "dev"
|
|
||||||
# source = "github.com/myfork/project2"
|
|
||||||
#
|
|
||||||
# [[override]]
|
|
||||||
# name = "github.com/x/y"
|
|
||||||
# version = "2.4.0"
|
|
||||||
#
|
|
||||||
# [prune]
|
|
||||||
# non-go = false
|
|
||||||
# go-tests = true
|
|
||||||
# unused-packages = true
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/go-gl/gl"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/go-gl/glfw"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "go.uber.org/zap"
|
|
||||||
version = "1.8.0"
|
|
||||||
|
|
||||||
[prune]
|
|
||||||
go-tests = true
|
|
||||||
unused-packages = true
|
|
||||||
|
|
||||||
[[prune.project]]
|
|
||||||
name = "github.com/go-gl/glfw"
|
|
||||||
unused-packages = false
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
module github.com/liamg/aminal
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/BurntSushi/toml v0.3.1
|
||||||
|
github.com/go-gl/gl v0.0.0-20181020191150-629e6eb0370b
|
||||||
|
github.com/go-gl/glfw v0.0.0-20181014061658-691ee1b84c51
|
||||||
|
github.com/gobuffalo/packr v1.13.7
|
||||||
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
|
||||||
|
github.com/kr/pty v1.1.3
|
||||||
|
github.com/riywo/loginshell v0.0.0-20130819055122-5da3acff0255
|
||||||
|
github.com/stretchr/testify v1.2.2
|
||||||
|
go.uber.org/atomic v1.3.2 // indirect
|
||||||
|
go.uber.org/multierr v1.1.0 // indirect
|
||||||
|
go.uber.org/zap v1.9.1
|
||||||
|
golang.org/x/image v0.0.0-20180926015637-991ec62608f3
|
||||||
|
)
|
|
@ -0,0 +1,35 @@
|
||||||
|
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
||||||
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/go-gl/gl v0.0.0-20181020191150-629e6eb0370b h1:dxIBr5pf89Lw0vPW6BInBZKILz55foJqU4NNyPXZxMI=
|
||||||
|
github.com/go-gl/gl v0.0.0-20181020191150-629e6eb0370b/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk=
|
||||||
|
github.com/go-gl/glfw v0.0.0-20181014061658-691ee1b84c51 h1:elGSwayRx7uAsfA5PnVKeTHh+AVsUTmas0CkHOw/DSk=
|
||||||
|
github.com/go-gl/glfw v0.0.0-20181014061658-691ee1b84c51/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
||||||
|
github.com/gobuffalo/packr v1.13.7 h1:2uZgLd6b/W4yRBZV/ScaORxZLNGMHO0VCvqQNkKukNA=
|
||||||
|
github.com/gobuffalo/packr v1.13.7/go.mod h1:KkinLIn/n6+3tVXMwg6KkNvWwVsrRAz4ph+jgpk3Z24=
|
||||||
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
||||||
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
||||||
|
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||||
|
github.com/kr/pty v1.1.3 h1:/Um6a/ZmD5tF7peoOJ5oN5KMQ0DrGVQSXLNwyckutPk=
|
||||||
|
github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
|
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
|
||||||
|
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/riywo/loginshell v0.0.0-20130819055122-5da3acff0255 h1:wE4Lc/2Tw9oMPFO7UeHhZgmzqPbjG9ilPe4e7VlBOog=
|
||||||
|
github.com/riywo/loginshell v0.0.0-20130819055122-5da3acff0255/go.mod h1:/PfPXh0EntGc3QAAyUaviy4S9tzy4Zp0e2ilq4voC6E=
|
||||||
|
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
|
||||||
|
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||||
|
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||||
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
|
go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4=
|
||||||
|
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||||
|
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
|
||||||
|
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
|
||||||
|
go.uber.org/zap v1.9.1 h1:XCJQEf3W6eZaVwhRBof6ImoYGJSITeKWsyeh3HFu/5o=
|
||||||
|
go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
||||||
|
golang.org/x/image v0.0.0-20180926015637-991ec62608f3 h1:5IfA9fqItkh2alJW94tvQk+6+RF9MW2q9DzwE8DBddQ=
|
||||||
|
golang.org/x/image v0.0.0-20180926015637-991ec62608f3/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
|
||||||
|
golang.org/x/net v0.0.0-20180921000356-2f5d2388922f/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
@ -1,61 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
|
||||||
)
|
|
||||||
|
|
||||||
type tomlConfig struct {
|
|
||||||
Title string
|
|
||||||
Owner ownerInfo
|
|
||||||
DB database `toml:"database"`
|
|
||||||
Servers map[string]server
|
|
||||||
Clients clients
|
|
||||||
}
|
|
||||||
|
|
||||||
type ownerInfo struct {
|
|
||||||
Name string
|
|
||||||
Org string `toml:"organization"`
|
|
||||||
Bio string
|
|
||||||
DOB time.Time
|
|
||||||
}
|
|
||||||
|
|
||||||
type database struct {
|
|
||||||
Server string
|
|
||||||
Ports []int
|
|
||||||
ConnMax int `toml:"connection_max"`
|
|
||||||
Enabled bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type server struct {
|
|
||||||
IP string
|
|
||||||
DC string
|
|
||||||
}
|
|
||||||
|
|
||||||
type clients struct {
|
|
||||||
Data [][]interface{}
|
|
||||||
Hosts []string
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
var config tomlConfig
|
|
||||||
if _, err := toml.DecodeFile("example.toml", &config); err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("Title: %s\n", config.Title)
|
|
||||||
fmt.Printf("Owner: %s (%s, %s), Born: %s\n",
|
|
||||||
config.Owner.Name, config.Owner.Org, config.Owner.Bio,
|
|
||||||
config.Owner.DOB)
|
|
||||||
fmt.Printf("Database: %s %v (Max conn. %d), Enabled? %v\n",
|
|
||||||
config.DB.Server, config.DB.Ports, config.DB.ConnMax,
|
|
||||||
config.DB.Enabled)
|
|
||||||
for serverName, server := range config.Servers {
|
|
||||||
fmt.Printf("Server: %s (%s, %s)\n", serverName, server.IP, server.DC)
|
|
||||||
}
|
|
||||||
fmt.Printf("Client data: %v\n", config.Clients.Data)
|
|
||||||
fmt.Printf("Client hosts: %v\n", config.Clients.Hosts)
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
# This is a TOML document. Boom.
|
|
||||||
|
|
||||||
title = "TOML Example"
|
|
||||||
|
|
||||||
[owner]
|
|
||||||
name = "Tom Preston-Werner"
|
|
||||||
organization = "GitHub"
|
|
||||||
bio = "GitHub Cofounder & CEO\nLikes tater tots and beer."
|
|
||||||
dob = 1979-05-27T07:32:00Z # First class dates? Why not?
|
|
||||||
|
|
||||||
[database]
|
|
||||||
server = "192.168.1.1"
|
|
||||||
ports = [ 8001, 8001, 8002 ]
|
|
||||||
connection_max = 5000
|
|
||||||
enabled = true
|
|
||||||
|
|
||||||
[servers]
|
|
||||||
|
|
||||||
# You can indent as you please. Tabs or spaces. TOML don't care.
|
|
||||||
[servers.alpha]
|
|
||||||
ip = "10.0.0.1"
|
|
||||||
dc = "eqdc10"
|
|
||||||
|
|
||||||
[servers.beta]
|
|
||||||
ip = "10.0.0.2"
|
|
||||||
dc = "eqdc10"
|
|
||||||
|
|
||||||
[clients]
|
|
||||||
data = [ ["gamma", "delta"], [1, 2] ] # just an update to make sure parsers support it
|
|
||||||
|
|
||||||
# Line breaks are OK when inside arrays
|
|
||||||
hosts = [
|
|
||||||
"alpha",
|
|
||||||
"omega"
|
|
||||||
]
|
|
|
@ -1,22 +0,0 @@
|
||||||
# Test file for TOML
|
|
||||||
# Only this one tries to emulate a TOML file written by a user of the kind of parser writers probably hate
|
|
||||||
# This part you'll really hate
|
|
||||||
|
|
||||||
[the]
|
|
||||||
test_string = "You'll hate me after this - #" # " Annoying, isn't it?
|
|
||||||
|
|
||||||
[the.hard]
|
|
||||||
test_array = [ "] ", " # "] # ] There you go, parse this!
|
|
||||||
test_array2 = [ "Test #11 ]proved that", "Experiment #9 was a success" ]
|
|
||||||
# You didn't think it'd as easy as chucking out the last #, did you?
|
|
||||||
another_test_string = " Same thing, but with a string #"
|
|
||||||
harder_test_string = " And when \"'s are in the string, along with # \"" # "and comments are there too"
|
|
||||||
# Things will get harder
|
|
||||||
|
|
||||||
[the.hard.bit#]
|
|
||||||
what? = "You don't think some user won't do that?"
|
|
||||||
multi_line_array = [
|
|
||||||
"]",
|
|
||||||
# ] Oh yes I did
|
|
||||||
]
|
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
# [x] you
|
|
||||||
# [x.y] don't
|
|
||||||
# [x.y.z] need these
|
|
||||||
[x.y.z.w] # for this to work
|
|
|
@ -1,6 +0,0 @@
|
||||||
# DO NOT WANT
|
|
||||||
[fruit]
|
|
||||||
type = "apple"
|
|
||||||
|
|
||||||
[fruit.type]
|
|
||||||
apple = "yes"
|
|
|
@ -1,35 +0,0 @@
|
||||||
# This is an INVALID TOML document. Boom.
|
|
||||||
# Can you spot the error without help?
|
|
||||||
|
|
||||||
title = "TOML Example"
|
|
||||||
|
|
||||||
[owner]
|
|
||||||
name = "Tom Preston-Werner"
|
|
||||||
organization = "GitHub"
|
|
||||||
bio = "GitHub Cofounder & CEO\nLikes tater tots and beer."
|
|
||||||
dob = 1979-05-27T7:32:00Z # First class dates? Why not?
|
|
||||||
|
|
||||||
[database]
|
|
||||||
server = "192.168.1.1"
|
|
||||||
ports = [ 8001, 8001, 8002 ]
|
|
||||||
connection_max = 5000
|
|
||||||
enabled = true
|
|
||||||
|
|
||||||
[servers]
|
|
||||||
# You can indent as you please. Tabs or spaces. TOML don't care.
|
|
||||||
[servers.alpha]
|
|
||||||
ip = "10.0.0.1"
|
|
||||||
dc = "eqdc10"
|
|
||||||
|
|
||||||
[servers.beta]
|
|
||||||
ip = "10.0.0.2"
|
|
||||||
dc = "eqdc10"
|
|
||||||
|
|
||||||
[clients]
|
|
||||||
data = [ ["gamma", "delta"], [1, 2] ] # just an update to make sure parsers support it
|
|
||||||
|
|
||||||
# Line breaks are OK when inside arrays
|
|
||||||
hosts = [
|
|
||||||
"alpha",
|
|
||||||
"omega"
|
|
||||||
]
|
|
|
@ -1,5 +0,0 @@
|
||||||
Age = 25
|
|
||||||
Cats = [ "Cauchy", "Plato" ]
|
|
||||||
Pi = 3.14
|
|
||||||
Perfection = [ 6, 28, 496, 8128 ]
|
|
||||||
DOB = 1987-07-05T05:45:00Z
|
|
|
@ -1 +0,0 @@
|
||||||
some_key_NAME = "wat"
|
|
|
@ -1,21 +0,0 @@
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2013 TOML authors
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
|
@ -1,13 +0,0 @@
|
||||||
# Implements the TOML test suite interface
|
|
||||||
|
|
||||||
This is an implementation of the interface expected by
|
|
||||||
[toml-test](https://github.com/BurntSushi/toml-test) for my
|
|
||||||
[toml parser written in Go](https://github.com/BurntSushi/toml).
|
|
||||||
In particular, it maps TOML data on `stdin` to a JSON format on `stdout`.
|
|
||||||
|
|
||||||
|
|
||||||
Compatible with TOML version
|
|
||||||
[v0.4.0](https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.4.0.md)
|
|
||||||
|
|
||||||
Compatible with `toml-test` version
|
|
||||||
[v0.2.0](https://github.com/BurntSushi/toml-test/tree/v0.2.0)
|
|
|
@ -1,90 +0,0 @@
|
||||||
// Command toml-test-decoder satisfies the toml-test interface for testing
|
|
||||||
// TOML decoders. Namely, it accepts TOML on stdin and outputs JSON on stdout.
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
log.SetFlags(0)
|
|
||||||
|
|
||||||
flag.Usage = usage
|
|
||||||
flag.Parse()
|
|
||||||
}
|
|
||||||
|
|
||||||
func usage() {
|
|
||||||
log.Printf("Usage: %s < toml-file\n", path.Base(os.Args[0]))
|
|
||||||
flag.PrintDefaults()
|
|
||||||
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
if flag.NArg() != 0 {
|
|
||||||
flag.Usage()
|
|
||||||
}
|
|
||||||
|
|
||||||
var tmp interface{}
|
|
||||||
if _, err := toml.DecodeReader(os.Stdin, &tmp); err != nil {
|
|
||||||
log.Fatalf("Error decoding TOML: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
typedTmp := translate(tmp)
|
|
||||||
if err := json.NewEncoder(os.Stdout).Encode(typedTmp); err != nil {
|
|
||||||
log.Fatalf("Error encoding JSON: %s", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func translate(tomlData interface{}) interface{} {
|
|
||||||
switch orig := tomlData.(type) {
|
|
||||||
case map[string]interface{}:
|
|
||||||
typed := make(map[string]interface{}, len(orig))
|
|
||||||
for k, v := range orig {
|
|
||||||
typed[k] = translate(v)
|
|
||||||
}
|
|
||||||
return typed
|
|
||||||
case []map[string]interface{}:
|
|
||||||
typed := make([]map[string]interface{}, len(orig))
|
|
||||||
for i, v := range orig {
|
|
||||||
typed[i] = translate(v).(map[string]interface{})
|
|
||||||
}
|
|
||||||
return typed
|
|
||||||
case []interface{}:
|
|
||||||
typed := make([]interface{}, len(orig))
|
|
||||||
for i, v := range orig {
|
|
||||||
typed[i] = translate(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
// We don't really need to tag arrays, but let's be future proof.
|
|
||||||
// (If TOML ever supports tuples, we'll need this.)
|
|
||||||
return tag("array", typed)
|
|
||||||
case time.Time:
|
|
||||||
return tag("datetime", orig.Format("2006-01-02T15:04:05Z"))
|
|
||||||
case bool:
|
|
||||||
return tag("bool", fmt.Sprintf("%v", orig))
|
|
||||||
case int64:
|
|
||||||
return tag("integer", fmt.Sprintf("%d", orig))
|
|
||||||
case float64:
|
|
||||||
return tag("float", fmt.Sprintf("%v", orig))
|
|
||||||
case string:
|
|
||||||
return tag("string", orig)
|
|
||||||
}
|
|
||||||
|
|
||||||
panic(fmt.Sprintf("Unknown type: %T", tomlData))
|
|
||||||
}
|
|
||||||
|
|
||||||
func tag(typeName string, data interface{}) map[string]interface{} {
|
|
||||||
return map[string]interface{}{
|
|
||||||
"type": typeName,
|
|
||||||
"value": data,
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2013 TOML authors
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
|
@ -1,13 +0,0 @@
|
||||||
# Implements the TOML test suite interface for TOML encoders
|
|
||||||
|
|
||||||
This is an implementation of the interface expected by
|
|
||||||
[toml-test](https://github.com/BurntSushi/toml-test) for the
|
|
||||||
[TOML encoder](https://github.com/BurntSushi/toml).
|
|
||||||
In particular, it maps JSON data on `stdin` to a TOML format on `stdout`.
|
|
||||||
|
|
||||||
|
|
||||||
Compatible with TOML version
|
|
||||||
[v0.4.0](https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.4.0.md)
|
|
||||||
|
|
||||||
Compatible with `toml-test` version
|
|
||||||
[v0.2.0](https://github.com/BurntSushi/toml-test/tree/v0.2.0)
|
|
|
@ -1,131 +0,0 @@
|
||||||
// Command toml-test-encoder satisfies the toml-test interface for testing
|
|
||||||
// TOML encoders. Namely, it accepts JSON on stdin and outputs TOML on stdout.
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"flag"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
log.SetFlags(0)
|
|
||||||
|
|
||||||
flag.Usage = usage
|
|
||||||
flag.Parse()
|
|
||||||
}
|
|
||||||
|
|
||||||
func usage() {
|
|
||||||
log.Printf("Usage: %s < json-file\n", path.Base(os.Args[0]))
|
|
||||||
flag.PrintDefaults()
|
|
||||||
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
if flag.NArg() != 0 {
|
|
||||||
flag.Usage()
|
|
||||||
}
|
|
||||||
|
|
||||||
var tmp interface{}
|
|
||||||
if err := json.NewDecoder(os.Stdin).Decode(&tmp); err != nil {
|
|
||||||
log.Fatalf("Error decoding JSON: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tomlData := translate(tmp)
|
|
||||||
if err := toml.NewEncoder(os.Stdout).Encode(tomlData); err != nil {
|
|
||||||
log.Fatalf("Error encoding TOML: %s", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func translate(typedJson interface{}) interface{} {
|
|
||||||
switch v := typedJson.(type) {
|
|
||||||
case map[string]interface{}:
|
|
||||||
if len(v) == 2 && in("type", v) && in("value", v) {
|
|
||||||
return untag(v)
|
|
||||||
}
|
|
||||||
m := make(map[string]interface{}, len(v))
|
|
||||||
for k, v2 := range v {
|
|
||||||
m[k] = translate(v2)
|
|
||||||
}
|
|
||||||
return m
|
|
||||||
case []interface{}:
|
|
||||||
tabArray := make([]map[string]interface{}, len(v))
|
|
||||||
for i := range v {
|
|
||||||
if m, ok := translate(v[i]).(map[string]interface{}); ok {
|
|
||||||
tabArray[i] = m
|
|
||||||
} else {
|
|
||||||
log.Fatalf("JSON arrays may only contain objects. This " +
|
|
||||||
"corresponds to only tables being allowed in " +
|
|
||||||
"TOML table arrays.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tabArray
|
|
||||||
}
|
|
||||||
log.Fatalf("Unrecognized JSON format '%T'.", typedJson)
|
|
||||||
panic("unreachable")
|
|
||||||
}
|
|
||||||
|
|
||||||
func untag(typed map[string]interface{}) interface{} {
|
|
||||||
t := typed["type"].(string)
|
|
||||||
v := typed["value"]
|
|
||||||
switch t {
|
|
||||||
case "string":
|
|
||||||
return v.(string)
|
|
||||||
case "integer":
|
|
||||||
v := v.(string)
|
|
||||||
n, err := strconv.Atoi(v)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not parse '%s' as integer: %s", v, err)
|
|
||||||
}
|
|
||||||
return n
|
|
||||||
case "float":
|
|
||||||
v := v.(string)
|
|
||||||
f, err := strconv.ParseFloat(v, 64)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not parse '%s' as float64: %s", v, err)
|
|
||||||
}
|
|
||||||
return f
|
|
||||||
case "datetime":
|
|
||||||
v := v.(string)
|
|
||||||
t, err := time.Parse("2006-01-02T15:04:05Z", v)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not parse '%s' as a datetime: %s", v, err)
|
|
||||||
}
|
|
||||||
return t
|
|
||||||
case "bool":
|
|
||||||
v := v.(string)
|
|
||||||
switch v {
|
|
||||||
case "true":
|
|
||||||
return true
|
|
||||||
case "false":
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
log.Fatalf("Could not parse '%s' as a boolean.", v)
|
|
||||||
case "array":
|
|
||||||
v := v.([]interface{})
|
|
||||||
array := make([]interface{}, len(v))
|
|
||||||
for i := range v {
|
|
||||||
if m, ok := v[i].(map[string]interface{}); ok {
|
|
||||||
array[i] = untag(m)
|
|
||||||
} else {
|
|
||||||
log.Fatalf("Arrays may only contain other arrays or "+
|
|
||||||
"primitive values, but found a '%T'.", m)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return array
|
|
||||||
}
|
|
||||||
log.Fatalf("Unrecognized tag type '%s'.", t)
|
|
||||||
panic("unreachable")
|
|
||||||
}
|
|
||||||
|
|
||||||
func in(key string, m map[string]interface{}) bool {
|
|
||||||
_, ok := m[key]
|
|
||||||
return ok
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2013 TOML authors
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
|
@ -1,21 +0,0 @@
|
||||||
# TOML Validator
|
|
||||||
|
|
||||||
If Go is installed, it's simple to try it out:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
go get github.com/BurntSushi/toml/cmd/tomlv
|
|
||||||
tomlv some-toml-file.toml
|
|
||||||
```
|
|
||||||
|
|
||||||
You can see the types of every key in a TOML file with:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
tomlv -types some-toml-file.toml
|
|
||||||
```
|
|
||||||
|
|
||||||
At the moment, only one error message is reported at a time. Error messages
|
|
||||||
include line numbers. No output means that the files given are valid TOML, or
|
|
||||||
there is a bug in `tomlv`.
|
|
||||||
|
|
||||||
Compatible with TOML version
|
|
||||||
[v0.4.0](https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.4.0.md)
|
|
|
@ -1,61 +0,0 @@
|
||||||
// Command tomlv validates TOML documents and prints each key's type.
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"strings"
|
|
||||||
"text/tabwriter"
|
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
flagTypes = false
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
log.SetFlags(0)
|
|
||||||
|
|
||||||
flag.BoolVar(&flagTypes, "types", flagTypes,
|
|
||||||
"When set, the types of every defined key will be shown.")
|
|
||||||
|
|
||||||
flag.Usage = usage
|
|
||||||
flag.Parse()
|
|
||||||
}
|
|
||||||
|
|
||||||
func usage() {
|
|
||||||
log.Printf("Usage: %s toml-file [ toml-file ... ]\n",
|
|
||||||
path.Base(os.Args[0]))
|
|
||||||
flag.PrintDefaults()
|
|
||||||
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
if flag.NArg() < 1 {
|
|
||||||
flag.Usage()
|
|
||||||
}
|
|
||||||
for _, f := range flag.Args() {
|
|
||||||
var tmp interface{}
|
|
||||||
md, err := toml.DecodeFile(f, &tmp)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Error in '%s': %s", f, err)
|
|
||||||
}
|
|
||||||
if flagTypes {
|
|
||||||
printTypes(md)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func printTypes(md toml.MetaData) {
|
|
||||||
tabw := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
|
||||||
for _, key := range md.Keys() {
|
|
||||||
fmt.Fprintf(tabw, "%s%s\t%s\n",
|
|
||||||
strings.Repeat(" ", len(key)-1), key, md.Type(key...))
|
|
||||||
}
|
|
||||||
tabw.Flush()
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,615 +0,0 @@
|
||||||
package toml
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"net"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestEncodeRoundTrip(t *testing.T) {
|
|
||||||
type Config struct {
|
|
||||||
Age int
|
|
||||||
Cats []string
|
|
||||||
Pi float64
|
|
||||||
Perfection []int
|
|
||||||
DOB time.Time
|
|
||||||
Ipaddress net.IP
|
|
||||||
}
|
|
||||||
|
|
||||||
var inputs = Config{
|
|
||||||
13,
|
|
||||||
[]string{"one", "two", "three"},
|
|
||||||
3.145,
|
|
||||||
[]int{11, 2, 3, 4},
|
|
||||||
time.Now(),
|
|
||||||
net.ParseIP("192.168.59.254"),
|
|
||||||
}
|
|
||||||
|
|
||||||
var firstBuffer bytes.Buffer
|
|
||||||
e := NewEncoder(&firstBuffer)
|
|
||||||
err := e.Encode(inputs)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
var outputs Config
|
|
||||||
if _, err := Decode(firstBuffer.String(), &outputs); err != nil {
|
|
||||||
t.Logf("Could not decode:\n-----\n%s\n-----\n",
|
|
||||||
firstBuffer.String())
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// could test each value individually, but I'm lazy
|
|
||||||
var secondBuffer bytes.Buffer
|
|
||||||
e2 := NewEncoder(&secondBuffer)
|
|
||||||
err = e2.Encode(outputs)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if firstBuffer.String() != secondBuffer.String() {
|
|
||||||
t.Error(
|
|
||||||
firstBuffer.String(),
|
|
||||||
"\n\n is not identical to\n\n",
|
|
||||||
secondBuffer.String())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXX(burntsushi)
|
|
||||||
// I think these tests probably should be removed. They are good, but they
|
|
||||||
// ought to be obsolete by toml-test.
|
|
||||||
func TestEncode(t *testing.T) {
|
|
||||||
type Embedded struct {
|
|
||||||
Int int `toml:"_int"`
|
|
||||||
}
|
|
||||||
type NonStruct int
|
|
||||||
|
|
||||||
date := time.Date(2014, 5, 11, 20, 30, 40, 0, time.FixedZone("IST", 3600))
|
|
||||||
dateStr := "2014-05-11T19:30:40Z"
|
|
||||||
|
|
||||||
tests := map[string]struct {
|
|
||||||
input interface{}
|
|
||||||
wantOutput string
|
|
||||||
wantError error
|
|
||||||
}{
|
|
||||||
"bool field": {
|
|
||||||
input: struct {
|
|
||||||
BoolTrue bool
|
|
||||||
BoolFalse bool
|
|
||||||
}{true, false},
|
|
||||||
wantOutput: "BoolTrue = true\nBoolFalse = false\n",
|
|
||||||
},
|
|
||||||
"int fields": {
|
|
||||||
input: struct {
|
|
||||||
Int int
|
|
||||||
Int8 int8
|
|
||||||
Int16 int16
|
|
||||||
Int32 int32
|
|
||||||
Int64 int64
|
|
||||||
}{1, 2, 3, 4, 5},
|
|
||||||
wantOutput: "Int = 1\nInt8 = 2\nInt16 = 3\nInt32 = 4\nInt64 = 5\n",
|
|
||||||
},
|
|
||||||
"uint fields": {
|
|
||||||
input: struct {
|
|
||||||
Uint uint
|
|
||||||
Uint8 uint8
|
|
||||||
Uint16 uint16
|
|
||||||
Uint32 uint32
|
|
||||||
Uint64 uint64
|
|
||||||
}{1, 2, 3, 4, 5},
|
|
||||||
wantOutput: "Uint = 1\nUint8 = 2\nUint16 = 3\nUint32 = 4" +
|
|
||||||
"\nUint64 = 5\n",
|
|
||||||
},
|
|
||||||
"float fields": {
|
|
||||||
input: struct {
|
|
||||||
Float32 float32
|
|
||||||
Float64 float64
|
|
||||||
}{1.5, 2.5},
|
|
||||||
wantOutput: "Float32 = 1.5\nFloat64 = 2.5\n",
|
|
||||||
},
|
|
||||||
"string field": {
|
|
||||||
input: struct{ String string }{"foo"},
|
|
||||||
wantOutput: "String = \"foo\"\n",
|
|
||||||
},
|
|
||||||
"string field and unexported field": {
|
|
||||||
input: struct {
|
|
||||||
String string
|
|
||||||
unexported int
|
|
||||||
}{"foo", 0},
|
|
||||||
wantOutput: "String = \"foo\"\n",
|
|
||||||
},
|
|
||||||
"datetime field in UTC": {
|
|
||||||
input: struct{ Date time.Time }{date},
|
|
||||||
wantOutput: fmt.Sprintf("Date = %s\n", dateStr),
|
|
||||||
},
|
|
||||||
"datetime field as primitive": {
|
|
||||||
// Using a map here to fail if isStructOrMap() returns true for
|
|
||||||
// time.Time.
|
|
||||||
input: map[string]interface{}{
|
|
||||||
"Date": date,
|
|
||||||
"Int": 1,
|
|
||||||
},
|
|
||||||
wantOutput: fmt.Sprintf("Date = %s\nInt = 1\n", dateStr),
|
|
||||||
},
|
|
||||||
"array fields": {
|
|
||||||
input: struct {
|
|
||||||
IntArray0 [0]int
|
|
||||||
IntArray3 [3]int
|
|
||||||
}{[0]int{}, [3]int{1, 2, 3}},
|
|
||||||
wantOutput: "IntArray0 = []\nIntArray3 = [1, 2, 3]\n",
|
|
||||||
},
|
|
||||||
"slice fields": {
|
|
||||||
input: struct{ IntSliceNil, IntSlice0, IntSlice3 []int }{
|
|
||||||
nil, []int{}, []int{1, 2, 3},
|
|
||||||
},
|
|
||||||
wantOutput: "IntSlice0 = []\nIntSlice3 = [1, 2, 3]\n",
|
|
||||||
},
|
|
||||||
"datetime slices": {
|
|
||||||
input: struct{ DatetimeSlice []time.Time }{
|
|
||||||
[]time.Time{date, date},
|
|
||||||
},
|
|
||||||
wantOutput: fmt.Sprintf("DatetimeSlice = [%s, %s]\n",
|
|
||||||
dateStr, dateStr),
|
|
||||||
},
|
|
||||||
"nested arrays and slices": {
|
|
||||||
input: struct {
|
|
||||||
SliceOfArrays [][2]int
|
|
||||||
ArrayOfSlices [2][]int
|
|
||||||
SliceOfArraysOfSlices [][2][]int
|
|
||||||
ArrayOfSlicesOfArrays [2][][2]int
|
|
||||||
SliceOfMixedArrays [][2]interface{}
|
|
||||||
ArrayOfMixedSlices [2][]interface{}
|
|
||||||
}{
|
|
||||||
[][2]int{{1, 2}, {3, 4}},
|
|
||||||
[2][]int{{1, 2}, {3, 4}},
|
|
||||||
[][2][]int{
|
|
||||||
{
|
|
||||||
{1, 2}, {3, 4},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
{5, 6}, {7, 8},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
[2][][2]int{
|
|
||||||
{
|
|
||||||
{1, 2}, {3, 4},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
{5, 6}, {7, 8},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
[][2]interface{}{
|
|
||||||
{1, 2}, {"a", "b"},
|
|
||||||
},
|
|
||||||
[2][]interface{}{
|
|
||||||
{1, 2}, {"a", "b"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
wantOutput: `SliceOfArrays = [[1, 2], [3, 4]]
|
|
||||||
ArrayOfSlices = [[1, 2], [3, 4]]
|
|
||||||
SliceOfArraysOfSlices = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
|
|
||||||
ArrayOfSlicesOfArrays = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
|
|
||||||
SliceOfMixedArrays = [[1, 2], ["a", "b"]]
|
|
||||||
ArrayOfMixedSlices = [[1, 2], ["a", "b"]]
|
|
||||||
`,
|
|
||||||
},
|
|
||||||
"empty slice": {
|
|
||||||
input: struct{ Empty []interface{} }{[]interface{}{}},
|
|
||||||
wantOutput: "Empty = []\n",
|
|
||||||
},
|
|
||||||
"(error) slice with element type mismatch (string and integer)": {
|
|
||||||
input: struct{ Mixed []interface{} }{[]interface{}{1, "a"}},
|
|
||||||
wantError: errArrayMixedElementTypes,
|
|
||||||
},
|
|
||||||
"(error) slice with element type mismatch (integer and float)": {
|
|
||||||
input: struct{ Mixed []interface{} }{[]interface{}{1, 2.5}},
|
|
||||||
wantError: errArrayMixedElementTypes,
|
|
||||||
},
|
|
||||||
"slice with elems of differing Go types, same TOML types": {
|
|
||||||
input: struct {
|
|
||||||
MixedInts []interface{}
|
|
||||||
MixedFloats []interface{}
|
|
||||||
}{
|
|
||||||
[]interface{}{
|
|
||||||
int(1), int8(2), int16(3), int32(4), int64(5),
|
|
||||||
uint(1), uint8(2), uint16(3), uint32(4), uint64(5),
|
|
||||||
},
|
|
||||||
[]interface{}{float32(1.5), float64(2.5)},
|
|
||||||
},
|
|
||||||
wantOutput: "MixedInts = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]\n" +
|
|
||||||
"MixedFloats = [1.5, 2.5]\n",
|
|
||||||
},
|
|
||||||
"(error) slice w/ element type mismatch (one is nested array)": {
|
|
||||||
input: struct{ Mixed []interface{} }{
|
|
||||||
[]interface{}{1, []interface{}{2}},
|
|
||||||
},
|
|
||||||
wantError: errArrayMixedElementTypes,
|
|
||||||
},
|
|
||||||
"(error) slice with 1 nil element": {
|
|
||||||
input: struct{ NilElement1 []interface{} }{[]interface{}{nil}},
|
|
||||||
wantError: errArrayNilElement,
|
|
||||||
},
|
|
||||||
"(error) slice with 1 nil element (and other non-nil elements)": {
|
|
||||||
input: struct{ NilElement []interface{} }{
|
|
||||||
[]interface{}{1, nil},
|
|
||||||
},
|
|
||||||
wantError: errArrayNilElement,
|
|
||||||
},
|
|
||||||
"simple map": {
|
|
||||||
input: map[string]int{"a": 1, "b": 2},
|
|
||||||
wantOutput: "a = 1\nb = 2\n",
|
|
||||||
},
|
|
||||||
"map with interface{} value type": {
|
|
||||||
input: map[string]interface{}{"a": 1, "b": "c"},
|
|
||||||
wantOutput: "a = 1\nb = \"c\"\n",
|
|
||||||
},
|
|
||||||
"map with interface{} value type, some of which are structs": {
|
|
||||||
input: map[string]interface{}{
|
|
||||||
"a": struct{ Int int }{2},
|
|
||||||
"b": 1,
|
|
||||||
},
|
|
||||||
wantOutput: "b = 1\n\n[a]\n Int = 2\n",
|
|
||||||
},
|
|
||||||
"nested map": {
|
|
||||||
input: map[string]map[string]int{
|
|
||||||
"a": {"b": 1},
|
|
||||||
"c": {"d": 2},
|
|
||||||
},
|
|
||||||
wantOutput: "[a]\n b = 1\n\n[c]\n d = 2\n",
|
|
||||||
},
|
|
||||||
"nested struct": {
|
|
||||||
input: struct{ Struct struct{ Int int } }{
|
|
||||||
struct{ Int int }{1},
|
|
||||||
},
|
|
||||||
wantOutput: "[Struct]\n Int = 1\n",
|
|
||||||
},
|
|
||||||
"nested struct and non-struct field": {
|
|
||||||
input: struct {
|
|
||||||
Struct struct{ Int int }
|
|
||||||
Bool bool
|
|
||||||
}{struct{ Int int }{1}, true},
|
|
||||||
wantOutput: "Bool = true\n\n[Struct]\n Int = 1\n",
|
|
||||||
},
|
|
||||||
"2 nested structs": {
|
|
||||||
input: struct{ Struct1, Struct2 struct{ Int int } }{
|
|
||||||
struct{ Int int }{1}, struct{ Int int }{2},
|
|
||||||
},
|
|
||||||
wantOutput: "[Struct1]\n Int = 1\n\n[Struct2]\n Int = 2\n",
|
|
||||||
},
|
|
||||||
"deeply nested structs": {
|
|
||||||
input: struct {
|
|
||||||
Struct1, Struct2 struct{ Struct3 *struct{ Int int } }
|
|
||||||
}{
|
|
||||||
struct{ Struct3 *struct{ Int int } }{&struct{ Int int }{1}},
|
|
||||||
struct{ Struct3 *struct{ Int int } }{nil},
|
|
||||||
},
|
|
||||||
wantOutput: "[Struct1]\n [Struct1.Struct3]\n Int = 1" +
|
|
||||||
"\n\n[Struct2]\n",
|
|
||||||
},
|
|
||||||
"nested struct with nil struct elem": {
|
|
||||||
input: struct {
|
|
||||||
Struct struct{ Inner *struct{ Int int } }
|
|
||||||
}{
|
|
||||||
struct{ Inner *struct{ Int int } }{nil},
|
|
||||||
},
|
|
||||||
wantOutput: "[Struct]\n",
|
|
||||||
},
|
|
||||||
"nested struct with no fields": {
|
|
||||||
input: struct {
|
|
||||||
Struct struct{ Inner struct{} }
|
|
||||||
}{
|
|
||||||
struct{ Inner struct{} }{struct{}{}},
|
|
||||||
},
|
|
||||||
wantOutput: "[Struct]\n [Struct.Inner]\n",
|
|
||||||
},
|
|
||||||
"struct with tags": {
|
|
||||||
input: struct {
|
|
||||||
Struct struct {
|
|
||||||
Int int `toml:"_int"`
|
|
||||||
} `toml:"_struct"`
|
|
||||||
Bool bool `toml:"_bool"`
|
|
||||||
}{
|
|
||||||
struct {
|
|
||||||
Int int `toml:"_int"`
|
|
||||||
}{1}, true,
|
|
||||||
},
|
|
||||||
wantOutput: "_bool = true\n\n[_struct]\n _int = 1\n",
|
|
||||||
},
|
|
||||||
"embedded struct": {
|
|
||||||
input: struct{ Embedded }{Embedded{1}},
|
|
||||||
wantOutput: "_int = 1\n",
|
|
||||||
},
|
|
||||||
"embedded *struct": {
|
|
||||||
input: struct{ *Embedded }{&Embedded{1}},
|
|
||||||
wantOutput: "_int = 1\n",
|
|
||||||
},
|
|
||||||
"nested embedded struct": {
|
|
||||||
input: struct {
|
|
||||||
Struct struct{ Embedded } `toml:"_struct"`
|
|
||||||
}{struct{ Embedded }{Embedded{1}}},
|
|
||||||
wantOutput: "[_struct]\n _int = 1\n",
|
|
||||||
},
|
|
||||||
"nested embedded *struct": {
|
|
||||||
input: struct {
|
|
||||||
Struct struct{ *Embedded } `toml:"_struct"`
|
|
||||||
}{struct{ *Embedded }{&Embedded{1}}},
|
|
||||||
wantOutput: "[_struct]\n _int = 1\n",
|
|
||||||
},
|
|
||||||
"embedded non-struct": {
|
|
||||||
input: struct{ NonStruct }{5},
|
|
||||||
wantOutput: "NonStruct = 5\n",
|
|
||||||
},
|
|
||||||
"array of tables": {
|
|
||||||
input: struct {
|
|
||||||
Structs []*struct{ Int int } `toml:"struct"`
|
|
||||||
}{
|
|
||||||
[]*struct{ Int int }{{1}, {3}},
|
|
||||||
},
|
|
||||||
wantOutput: "[[struct]]\n Int = 1\n\n[[struct]]\n Int = 3\n",
|
|
||||||
},
|
|
||||||
"array of tables order": {
|
|
||||||
input: map[string]interface{}{
|
|
||||||
"map": map[string]interface{}{
|
|
||||||
"zero": 5,
|
|
||||||
"arr": []map[string]int{
|
|
||||||
{
|
|
||||||
"friend": 5,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
wantOutput: "[map]\n zero = 5\n\n [[map.arr]]\n friend = 5\n",
|
|
||||||
},
|
|
||||||
"(error) top-level slice": {
|
|
||||||
input: []struct{ Int int }{{1}, {2}, {3}},
|
|
||||||
wantError: errNoKey,
|
|
||||||
},
|
|
||||||
"(error) slice of slice": {
|
|
||||||
input: struct {
|
|
||||||
Slices [][]struct{ Int int }
|
|
||||||
}{
|
|
||||||
[][]struct{ Int int }{{{1}}, {{2}}, {{3}}},
|
|
||||||
},
|
|
||||||
wantError: errArrayNoTable,
|
|
||||||
},
|
|
||||||
"(error) map no string key": {
|
|
||||||
input: map[int]string{1: ""},
|
|
||||||
wantError: errNonString,
|
|
||||||
},
|
|
||||||
"(error) empty key name": {
|
|
||||||
input: map[string]int{"": 1},
|
|
||||||
wantError: errAnything,
|
|
||||||
},
|
|
||||||
"(error) empty map name": {
|
|
||||||
input: map[string]interface{}{
|
|
||||||
"": map[string]int{"v": 1},
|
|
||||||
},
|
|
||||||
wantError: errAnything,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for label, test := range tests {
|
|
||||||
encodeExpected(t, label, test.input, test.wantOutput, test.wantError)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEncodeNestedTableArrays(t *testing.T) {
|
|
||||||
type song struct {
|
|
||||||
Name string `toml:"name"`
|
|
||||||
}
|
|
||||||
type album struct {
|
|
||||||
Name string `toml:"name"`
|
|
||||||
Songs []song `toml:"songs"`
|
|
||||||
}
|
|
||||||
type springsteen struct {
|
|
||||||
Albums []album `toml:"albums"`
|
|
||||||
}
|
|
||||||
value := springsteen{
|
|
||||||
[]album{
|
|
||||||
{"Born to Run",
|
|
||||||
[]song{{"Jungleland"}, {"Meeting Across the River"}}},
|
|
||||||
{"Born in the USA",
|
|
||||||
[]song{{"Glory Days"}, {"Dancing in the Dark"}}},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
expected := `[[albums]]
|
|
||||||
name = "Born to Run"
|
|
||||||
|
|
||||||
[[albums.songs]]
|
|
||||||
name = "Jungleland"
|
|
||||||
|
|
||||||
[[albums.songs]]
|
|
||||||
name = "Meeting Across the River"
|
|
||||||
|
|
||||||
[[albums]]
|
|
||||||
name = "Born in the USA"
|
|
||||||
|
|
||||||
[[albums.songs]]
|
|
||||||
name = "Glory Days"
|
|
||||||
|
|
||||||
[[albums.songs]]
|
|
||||||
name = "Dancing in the Dark"
|
|
||||||
`
|
|
||||||
encodeExpected(t, "nested table arrays", value, expected, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEncodeArrayHashWithNormalHashOrder(t *testing.T) {
|
|
||||||
type Alpha struct {
|
|
||||||
V int
|
|
||||||
}
|
|
||||||
type Beta struct {
|
|
||||||
V int
|
|
||||||
}
|
|
||||||
type Conf struct {
|
|
||||||
V int
|
|
||||||
A Alpha
|
|
||||||
B []Beta
|
|
||||||
}
|
|
||||||
|
|
||||||
val := Conf{
|
|
||||||
V: 1,
|
|
||||||
A: Alpha{2},
|
|
||||||
B: []Beta{{3}},
|
|
||||||
}
|
|
||||||
expected := "V = 1\n\n[A]\n V = 2\n\n[[B]]\n V = 3\n"
|
|
||||||
encodeExpected(t, "array hash with normal hash order", val, expected, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEncodeWithOmitEmpty(t *testing.T) {
|
|
||||||
type simple struct {
|
|
||||||
Bool bool `toml:"bool,omitempty"`
|
|
||||||
String string `toml:"string,omitempty"`
|
|
||||||
Array [0]byte `toml:"array,omitempty"`
|
|
||||||
Slice []int `toml:"slice,omitempty"`
|
|
||||||
Map map[string]string `toml:"map,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
var v simple
|
|
||||||
encodeExpected(t, "fields with omitempty are omitted when empty", v, "", nil)
|
|
||||||
v = simple{
|
|
||||||
Bool: true,
|
|
||||||
String: " ",
|
|
||||||
Slice: []int{2, 3, 4},
|
|
||||||
Map: map[string]string{"foo": "bar"},
|
|
||||||
}
|
|
||||||
expected := `bool = true
|
|
||||||
string = " "
|
|
||||||
slice = [2, 3, 4]
|
|
||||||
|
|
||||||
[map]
|
|
||||||
foo = "bar"
|
|
||||||
`
|
|
||||||
encodeExpected(t, "fields with omitempty are not omitted when non-empty",
|
|
||||||
v, expected, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEncodeWithOmitZero(t *testing.T) {
|
|
||||||
type simple struct {
|
|
||||||
Number int `toml:"number,omitzero"`
|
|
||||||
Real float64 `toml:"real,omitzero"`
|
|
||||||
Unsigned uint `toml:"unsigned,omitzero"`
|
|
||||||
}
|
|
||||||
|
|
||||||
value := simple{0, 0.0, uint(0)}
|
|
||||||
expected := ""
|
|
||||||
|
|
||||||
encodeExpected(t, "simple with omitzero, all zero", value, expected, nil)
|
|
||||||
|
|
||||||
value.Number = 10
|
|
||||||
value.Real = 20
|
|
||||||
value.Unsigned = 5
|
|
||||||
expected = `number = 10
|
|
||||||
real = 20.0
|
|
||||||
unsigned = 5
|
|
||||||
`
|
|
||||||
encodeExpected(t, "simple with omitzero, non-zero", value, expected, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEncodeOmitemptyWithEmptyName(t *testing.T) {
|
|
||||||
type simple struct {
|
|
||||||
S []int `toml:",omitempty"`
|
|
||||||
}
|
|
||||||
v := simple{[]int{1, 2, 3}}
|
|
||||||
expected := "S = [1, 2, 3]\n"
|
|
||||||
encodeExpected(t, "simple with omitempty, no name, non-empty field",
|
|
||||||
v, expected, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEncodeAnonymousStruct(t *testing.T) {
|
|
||||||
type Inner struct{ N int }
|
|
||||||
type Outer0 struct{ Inner }
|
|
||||||
type Outer1 struct {
|
|
||||||
Inner `toml:"inner"`
|
|
||||||
}
|
|
||||||
|
|
||||||
v0 := Outer0{Inner{3}}
|
|
||||||
expected := "N = 3\n"
|
|
||||||
encodeExpected(t, "embedded anonymous untagged struct", v0, expected, nil)
|
|
||||||
|
|
||||||
v1 := Outer1{Inner{3}}
|
|
||||||
expected = "[inner]\n N = 3\n"
|
|
||||||
encodeExpected(t, "embedded anonymous tagged struct", v1, expected, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEncodeAnonymousStructPointerField(t *testing.T) {
|
|
||||||
type Inner struct{ N int }
|
|
||||||
type Outer0 struct{ *Inner }
|
|
||||||
type Outer1 struct {
|
|
||||||
*Inner `toml:"inner"`
|
|
||||||
}
|
|
||||||
|
|
||||||
v0 := Outer0{}
|
|
||||||
expected := ""
|
|
||||||
encodeExpected(t, "nil anonymous untagged struct pointer field", v0, expected, nil)
|
|
||||||
|
|
||||||
v0 = Outer0{&Inner{3}}
|
|
||||||
expected = "N = 3\n"
|
|
||||||
encodeExpected(t, "non-nil anonymous untagged struct pointer field", v0, expected, nil)
|
|
||||||
|
|
||||||
v1 := Outer1{}
|
|
||||||
expected = ""
|
|
||||||
encodeExpected(t, "nil anonymous tagged struct pointer field", v1, expected, nil)
|
|
||||||
|
|
||||||
v1 = Outer1{&Inner{3}}
|
|
||||||
expected = "[inner]\n N = 3\n"
|
|
||||||
encodeExpected(t, "non-nil anonymous tagged struct pointer field", v1, expected, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEncodeIgnoredFields(t *testing.T) {
|
|
||||||
type simple struct {
|
|
||||||
Number int `toml:"-"`
|
|
||||||
}
|
|
||||||
value := simple{}
|
|
||||||
expected := ""
|
|
||||||
encodeExpected(t, "ignored field", value, expected, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeExpected(
|
|
||||||
t *testing.T, label string, val interface{}, wantStr string, wantErr error,
|
|
||||||
) {
|
|
||||||
var buf bytes.Buffer
|
|
||||||
enc := NewEncoder(&buf)
|
|
||||||
err := enc.Encode(val)
|
|
||||||
if err != wantErr {
|
|
||||||
if wantErr != nil {
|
|
||||||
if wantErr == errAnything && err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
t.Errorf("%s: want Encode error %v, got %v", label, wantErr, err)
|
|
||||||
} else {
|
|
||||||
t.Errorf("%s: Encode failed: %s", label, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if got := buf.String(); wantStr != got {
|
|
||||||
t.Errorf("%s: want\n-----\n%q\n-----\nbut got\n-----\n%q\n-----\n",
|
|
||||||
label, wantStr, got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExampleEncoder_Encode() {
|
|
||||||
date, _ := time.Parse(time.RFC822, "14 Mar 10 18:00 UTC")
|
|
||||||
var config = map[string]interface{}{
|
|
||||||
"date": date,
|
|
||||||
"counts": []int{1, 1, 2, 3, 5, 8},
|
|
||||||
"hash": map[string]string{
|
|
||||||
"key1": "val1",
|
|
||||||
"key2": "val2",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
if err := NewEncoder(buf).Encode(config); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
fmt.Println(buf.String())
|
|
||||||
|
|
||||||
// Output:
|
|
||||||
// counts = [1, 1, 2, 3, 5, 8]
|
|
||||||
// date = 2010-03-14T18:00:00Z
|
|
||||||
//
|
|
||||||
// [hash]
|
|
||||||
// key1 = "val1"
|
|
||||||
// key2 = "val2"
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
|
||||||
*.o
|
|
||||||
*.a
|
|
||||||
*.so
|
|
||||||
|
|
||||||
# Folders
|
|
||||||
_obj
|
|
||||||
_test
|
|
||||||
|
|
||||||
# Architecture specific extensions/prefixes
|
|
||||||
*.[568vq]
|
|
||||||
[568vq].out
|
|
||||||
|
|
||||||
*.cgo1.go
|
|
||||||
*.cgo2.c
|
|
||||||
_cgo_defun.c
|
|
||||||
_cgo_gotypes.go
|
|
||||||
_cgo_export.*
|
|
||||||
|
|
||||||
_testmain.go
|
|
||||||
|
|
||||||
*.exe
|
|
|
@ -1,28 +0,0 @@
|
||||||
language: go
|
|
||||||
go_import_path: github.com/davecgh/go-spew
|
|
||||||
go:
|
|
||||||
- 1.6.x
|
|
||||||
- 1.7.x
|
|
||||||
- 1.8.x
|
|
||||||
- 1.9.x
|
|
||||||
- 1.10.x
|
|
||||||
- tip
|
|
||||||
sudo: false
|
|
||||||
install:
|
|
||||||
- go get -v github.com/alecthomas/gometalinter
|
|
||||||
- gometalinter --install
|
|
||||||
script:
|
|
||||||
- export PATH=$PATH:$HOME/gopath/bin
|
|
||||||
- export GORACE="halt_on_error=1"
|
|
||||||
- test -z "$(gometalinter --disable-all
|
|
||||||
--enable=gofmt
|
|
||||||
--enable=golint
|
|
||||||
--enable=vet
|
|
||||||
--enable=gosimple
|
|
||||||
--enable=unconvert
|
|
||||||
--deadline=4m ./spew | tee /dev/stderr)"
|
|
||||||
- go test -v -race -tags safe ./spew
|
|
||||||
- go test -v -race -tags testcgo ./spew -covermode=atomic -coverprofile=profile.cov
|
|
||||||
after_success:
|
|
||||||
- go get -v github.com/mattn/goveralls
|
|
||||||
- goveralls -coverprofile=profile.cov -service=travis-ci
|
|
|
@ -1,201 +0,0 @@
|
||||||
go-spew
|
|
||||||
=======
|
|
||||||
|
|
||||||
[](https://travis-ci.org/davecgh/go-spew)
|
|
||||||
[](http://copyfree.org)
|
|
||||||
[](https://coveralls.io/r/davecgh/go-spew?branch=master)
|
|
||||||
|
|
||||||
Go-spew implements a deep pretty printer for Go data structures to aid in
|
|
||||||
debugging. A comprehensive suite of tests with 100% test coverage is provided
|
|
||||||
to ensure proper functionality. See `test_coverage.txt` for the gocov coverage
|
|
||||||
report. Go-spew is licensed under the liberal ISC license, so it may be used in
|
|
||||||
open source or commercial projects.
|
|
||||||
|
|
||||||
If you're interested in reading about how this package came to life and some
|
|
||||||
of the challenges involved in providing a deep pretty printer, there is a blog
|
|
||||||
post about it
|
|
||||||
[here](https://web.archive.org/web/20160304013555/https://blog.cyphertite.com/go-spew-a-journey-into-dumping-go-data-structures/).
|
|
||||||
|
|
||||||
## Documentation
|
|
||||||
|
|
||||||
[](http://godoc.org/github.com/davecgh/go-spew/spew)
|
|
||||||
|
|
||||||
Full `go doc` style documentation for the project can be viewed online without
|
|
||||||
installing this package by using the excellent GoDoc site here:
|
|
||||||
http://godoc.org/github.com/davecgh/go-spew/spew
|
|
||||||
|
|
||||||
You can also view the documentation locally once the package is installed with
|
|
||||||
the `godoc` tool by running `godoc -http=":6060"` and pointing your browser to
|
|
||||||
http://localhost:6060/pkg/github.com/davecgh/go-spew/spew
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ go get -u github.com/davecgh/go-spew/spew
|
|
||||||
```
|
|
||||||
|
|
||||||
## Quick Start
|
|
||||||
|
|
||||||
Add this import line to the file you're working in:
|
|
||||||
|
|
||||||
```Go
|
|
||||||
import "github.com/davecgh/go-spew/spew"
|
|
||||||
```
|
|
||||||
|
|
||||||
To dump a variable with full newlines, indentation, type, and pointer
|
|
||||||
information use Dump, Fdump, or Sdump:
|
|
||||||
|
|
||||||
```Go
|
|
||||||
spew.Dump(myVar1, myVar2, ...)
|
|
||||||
spew.Fdump(someWriter, myVar1, myVar2, ...)
|
|
||||||
str := spew.Sdump(myVar1, myVar2, ...)
|
|
||||||
```
|
|
||||||
|
|
||||||
Alternatively, if you would prefer to use format strings with a compacted inline
|
|
||||||
printing style, use the convenience wrappers Printf, Fprintf, etc with %v (most
|
|
||||||
compact), %+v (adds pointer addresses), %#v (adds types), or %#+v (adds types
|
|
||||||
and pointer addresses):
|
|
||||||
|
|
||||||
```Go
|
|
||||||
spew.Printf("myVar1: %v -- myVar2: %+v", myVar1, myVar2)
|
|
||||||
spew.Printf("myVar3: %#v -- myVar4: %#+v", myVar3, myVar4)
|
|
||||||
spew.Fprintf(someWriter, "myVar1: %v -- myVar2: %+v", myVar1, myVar2)
|
|
||||||
spew.Fprintf(someWriter, "myVar3: %#v -- myVar4: %#+v", myVar3, myVar4)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Debugging a Web Application Example
|
|
||||||
|
|
||||||
Here is an example of how you can use `spew.Sdump()` to help debug a web application. Please be sure to wrap your output using the `html.EscapeString()` function for safety reasons. You should also only use this debugging technique in a development environment, never in production.
|
|
||||||
|
|
||||||
```Go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"html"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
|
||||||
)
|
|
||||||
|
|
||||||
func handler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/html")
|
|
||||||
fmt.Fprintf(w, "Hi there, %s!", r.URL.Path[1:])
|
|
||||||
fmt.Fprintf(w, "<!--\n" + html.EscapeString(spew.Sdump(w)) + "\n-->")
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", handler)
|
|
||||||
http.ListenAndServe(":8080", nil)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Sample Dump Output
|
|
||||||
|
|
||||||
```
|
|
||||||
(main.Foo) {
|
|
||||||
unexportedField: (*main.Bar)(0xf84002e210)({
|
|
||||||
flag: (main.Flag) flagTwo,
|
|
||||||
data: (uintptr) <nil>
|
|
||||||
}),
|
|
||||||
ExportedField: (map[interface {}]interface {}) {
|
|
||||||
(string) "one": (bool) true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
([]uint8) {
|
|
||||||
00000000 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 |............... |
|
|
||||||
00000010 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 |!"#$%&'()*+,-./0|
|
|
||||||
00000020 31 32 |12|
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Sample Formatter Output
|
|
||||||
|
|
||||||
Double pointer to a uint8:
|
|
||||||
```
|
|
||||||
%v: <**>5
|
|
||||||
%+v: <**>(0xf8400420d0->0xf8400420c8)5
|
|
||||||
%#v: (**uint8)5
|
|
||||||
%#+v: (**uint8)(0xf8400420d0->0xf8400420c8)5
|
|
||||||
```
|
|
||||||
|
|
||||||
Pointer to circular struct with a uint8 field and a pointer to itself:
|
|
||||||
```
|
|
||||||
%v: <*>{1 <*><shown>}
|
|
||||||
%+v: <*>(0xf84003e260){ui8:1 c:<*>(0xf84003e260)<shown>}
|
|
||||||
%#v: (*main.circular){ui8:(uint8)1 c:(*main.circular)<shown>}
|
|
||||||
%#+v: (*main.circular)(0xf84003e260){ui8:(uint8)1 c:(*main.circular)(0xf84003e260)<shown>}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Configuration Options
|
|
||||||
|
|
||||||
Configuration of spew is handled by fields in the ConfigState type. For
|
|
||||||
convenience, all of the top-level functions use a global state available via the
|
|
||||||
spew.Config global.
|
|
||||||
|
|
||||||
It is also possible to create a ConfigState instance that provides methods
|
|
||||||
equivalent to the top-level functions. This allows concurrent configuration
|
|
||||||
options. See the ConfigState documentation for more details.
|
|
||||||
|
|
||||||
```
|
|
||||||
* Indent
|
|
||||||
String to use for each indentation level for Dump functions.
|
|
||||||
It is a single space by default. A popular alternative is "\t".
|
|
||||||
|
|
||||||
* MaxDepth
|
|
||||||
Maximum number of levels to descend into nested data structures.
|
|
||||||
There is no limit by default.
|
|
||||||
|
|
||||||
* DisableMethods
|
|
||||||
Disables invocation of error and Stringer interface methods.
|
|
||||||
Method invocation is enabled by default.
|
|
||||||
|
|
||||||
* DisablePointerMethods
|
|
||||||
Disables invocation of error and Stringer interface methods on types
|
|
||||||
which only accept pointer receivers from non-pointer variables. This option
|
|
||||||
relies on access to the unsafe package, so it will not have any effect when
|
|
||||||
running in environments without access to the unsafe package such as Google
|
|
||||||
App Engine or with the "safe" build tag specified.
|
|
||||||
Pointer method invocation is enabled by default.
|
|
||||||
|
|
||||||
* DisablePointerAddresses
|
|
||||||
DisablePointerAddresses specifies whether to disable the printing of
|
|
||||||
pointer addresses. This is useful when diffing data structures in tests.
|
|
||||||
|
|
||||||
* DisableCapacities
|
|
||||||
DisableCapacities specifies whether to disable the printing of capacities
|
|
||||||
for arrays, slices, maps and channels. This is useful when diffing data
|
|
||||||
structures in tests.
|
|
||||||
|
|
||||||
* ContinueOnMethod
|
|
||||||
Enables recursion into types after invoking error and Stringer interface
|
|
||||||
methods. Recursion after method invocation is disabled by default.
|
|
||||||
|
|
||||||
* SortKeys
|
|
||||||
Specifies map keys should be sorted before being printed. Use
|
|
||||||
this to have a more deterministic, diffable output. Note that
|
|
||||||
only native types (bool, int, uint, floats, uintptr and string)
|
|
||||||
and types which implement error or Stringer interfaces are supported,
|
|
||||||
with other types sorted according to the reflect.Value.String() output
|
|
||||||
which guarantees display stability. Natural map order is used by
|
|
||||||
default.
|
|
||||||
|
|
||||||
* SpewKeys
|
|
||||||
SpewKeys specifies that, as a last resort attempt, map keys should be
|
|
||||||
spewed to strings and sorted by those strings. This is only considered
|
|
||||||
if SortKeys is true.
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
## Unsafe Package Dependency
|
|
||||||
|
|
||||||
This package relies on the unsafe package to perform some of the more advanced
|
|
||||||
features, however it also supports a "limited" mode which allows it to work in
|
|
||||||
environments where the unsafe package is not available. By default, it will
|
|
||||||
operate in this mode on Google App Engine and when compiled with GopherJS. The
|
|
||||||
"safe" build tag may also be specified to force the package to build without
|
|
||||||
using the unsafe package.
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
Go-spew is licensed under the [copyfree](http://copyfree.org) ISC License.
|
|
|
@ -1,22 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# This script uses gocov to generate a test coverage report.
|
|
||||||
# The gocov tool my be obtained with the following command:
|
|
||||||
# go get github.com/axw/gocov/gocov
|
|
||||||
#
|
|
||||||
# It will be installed to $GOPATH/bin, so ensure that location is in your $PATH.
|
|
||||||
|
|
||||||
# Check for gocov.
|
|
||||||
if ! type gocov >/dev/null 2>&1; then
|
|
||||||
echo >&2 "This script requires the gocov tool."
|
|
||||||
echo >&2 "You may obtain it with the following command:"
|
|
||||||
echo >&2 "go get github.com/axw/gocov/gocov"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Only run the cgo tests if gcc is installed.
|
|
||||||
if type gcc >/dev/null 2>&1; then
|
|
||||||
(cd spew && gocov test -tags testcgo | gocov report)
|
|
||||||
else
|
|
||||||
(cd spew && gocov test | gocov report)
|
|
||||||
fi
|
|
|
@ -1,298 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package spew_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
|
||||||
)
|
|
||||||
|
|
||||||
// custom type to test Stinger interface on non-pointer receiver.
|
|
||||||
type stringer string
|
|
||||||
|
|
||||||
// String implements the Stringer interface for testing invocation of custom
|
|
||||||
// stringers on types with non-pointer receivers.
|
|
||||||
func (s stringer) String() string {
|
|
||||||
return "stringer " + string(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
// custom type to test Stinger interface on pointer receiver.
|
|
||||||
type pstringer string
|
|
||||||
|
|
||||||
// String implements the Stringer interface for testing invocation of custom
|
|
||||||
// stringers on types with only pointer receivers.
|
|
||||||
func (s *pstringer) String() string {
|
|
||||||
return "stringer " + string(*s)
|
|
||||||
}
|
|
||||||
|
|
||||||
// xref1 and xref2 are cross referencing structs for testing circular reference
|
|
||||||
// detection.
|
|
||||||
type xref1 struct {
|
|
||||||
ps2 *xref2
|
|
||||||
}
|
|
||||||
type xref2 struct {
|
|
||||||
ps1 *xref1
|
|
||||||
}
|
|
||||||
|
|
||||||
// indirCir1, indirCir2, and indirCir3 are used to generate an indirect circular
|
|
||||||
// reference for testing detection.
|
|
||||||
type indirCir1 struct {
|
|
||||||
ps2 *indirCir2
|
|
||||||
}
|
|
||||||
type indirCir2 struct {
|
|
||||||
ps3 *indirCir3
|
|
||||||
}
|
|
||||||
type indirCir3 struct {
|
|
||||||
ps1 *indirCir1
|
|
||||||
}
|
|
||||||
|
|
||||||
// embed is used to test embedded structures.
|
|
||||||
type embed struct {
|
|
||||||
a string
|
|
||||||
}
|
|
||||||
|
|
||||||
// embedwrap is used to test embedded structures.
|
|
||||||
type embedwrap struct {
|
|
||||||
*embed
|
|
||||||
e *embed
|
|
||||||
}
|
|
||||||
|
|
||||||
// panicer is used to intentionally cause a panic for testing spew properly
|
|
||||||
// handles them
|
|
||||||
type panicer int
|
|
||||||
|
|
||||||
func (p panicer) String() string {
|
|
||||||
panic("test panic")
|
|
||||||
}
|
|
||||||
|
|
||||||
// customError is used to test custom error interface invocation.
|
|
||||||
type customError int
|
|
||||||
|
|
||||||
func (e customError) Error() string {
|
|
||||||
return fmt.Sprintf("error: %d", int(e))
|
|
||||||
}
|
|
||||||
|
|
||||||
// stringizeWants converts a slice of wanted test output into a format suitable
|
|
||||||
// for a test error message.
|
|
||||||
func stringizeWants(wants []string) string {
|
|
||||||
s := ""
|
|
||||||
for i, want := range wants {
|
|
||||||
if i > 0 {
|
|
||||||
s += fmt.Sprintf("want%d: %s", i+1, want)
|
|
||||||
} else {
|
|
||||||
s += "want: " + want
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// testFailed returns whether or not a test failed by checking if the result
|
|
||||||
// of the test is in the slice of wanted strings.
|
|
||||||
func testFailed(result string, wants []string) bool {
|
|
||||||
for _, want := range wants {
|
|
||||||
if result == want {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
type sortableStruct struct {
|
|
||||||
x int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ss sortableStruct) String() string {
|
|
||||||
return fmt.Sprintf("ss.%d", ss.x)
|
|
||||||
}
|
|
||||||
|
|
||||||
type unsortableStruct struct {
|
|
||||||
x int
|
|
||||||
}
|
|
||||||
|
|
||||||
type sortTestCase struct {
|
|
||||||
input []reflect.Value
|
|
||||||
expected []reflect.Value
|
|
||||||
}
|
|
||||||
|
|
||||||
func helpTestSortValues(tests []sortTestCase, cs *spew.ConfigState, t *testing.T) {
|
|
||||||
getInterfaces := func(values []reflect.Value) []interface{} {
|
|
||||||
interfaces := []interface{}{}
|
|
||||||
for _, v := range values {
|
|
||||||
interfaces = append(interfaces, v.Interface())
|
|
||||||
}
|
|
||||||
return interfaces
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, test := range tests {
|
|
||||||
spew.SortValues(test.input, cs)
|
|
||||||
// reflect.DeepEqual cannot really make sense of reflect.Value,
|
|
||||||
// probably because of all the pointer tricks. For instance,
|
|
||||||
// v(2.0) != v(2.0) on a 32-bits system. Turn them into interface{}
|
|
||||||
// instead.
|
|
||||||
input := getInterfaces(test.input)
|
|
||||||
expected := getInterfaces(test.expected)
|
|
||||||
if !reflect.DeepEqual(input, expected) {
|
|
||||||
t.Errorf("Sort mismatch:\n %v != %v", input, expected)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestSortValues ensures the sort functionality for relect.Value based sorting
|
|
||||||
// works as intended.
|
|
||||||
func TestSortValues(t *testing.T) {
|
|
||||||
v := reflect.ValueOf
|
|
||||||
|
|
||||||
a := v("a")
|
|
||||||
b := v("b")
|
|
||||||
c := v("c")
|
|
||||||
embedA := v(embed{"a"})
|
|
||||||
embedB := v(embed{"b"})
|
|
||||||
embedC := v(embed{"c"})
|
|
||||||
tests := []sortTestCase{
|
|
||||||
// No values.
|
|
||||||
{
|
|
||||||
[]reflect.Value{},
|
|
||||||
[]reflect.Value{},
|
|
||||||
},
|
|
||||||
// Bools.
|
|
||||||
{
|
|
||||||
[]reflect.Value{v(false), v(true), v(false)},
|
|
||||||
[]reflect.Value{v(false), v(false), v(true)},
|
|
||||||
},
|
|
||||||
// Ints.
|
|
||||||
{
|
|
||||||
[]reflect.Value{v(2), v(1), v(3)},
|
|
||||||
[]reflect.Value{v(1), v(2), v(3)},
|
|
||||||
},
|
|
||||||
// Uints.
|
|
||||||
{
|
|
||||||
[]reflect.Value{v(uint8(2)), v(uint8(1)), v(uint8(3))},
|
|
||||||
[]reflect.Value{v(uint8(1)), v(uint8(2)), v(uint8(3))},
|
|
||||||
},
|
|
||||||
// Floats.
|
|
||||||
{
|
|
||||||
[]reflect.Value{v(2.0), v(1.0), v(3.0)},
|
|
||||||
[]reflect.Value{v(1.0), v(2.0), v(3.0)},
|
|
||||||
},
|
|
||||||
// Strings.
|
|
||||||
{
|
|
||||||
[]reflect.Value{b, a, c},
|
|
||||||
[]reflect.Value{a, b, c},
|
|
||||||
},
|
|
||||||
// Array
|
|
||||||
{
|
|
||||||
[]reflect.Value{v([3]int{3, 2, 1}), v([3]int{1, 3, 2}), v([3]int{1, 2, 3})},
|
|
||||||
[]reflect.Value{v([3]int{1, 2, 3}), v([3]int{1, 3, 2}), v([3]int{3, 2, 1})},
|
|
||||||
},
|
|
||||||
// Uintptrs.
|
|
||||||
{
|
|
||||||
[]reflect.Value{v(uintptr(2)), v(uintptr(1)), v(uintptr(3))},
|
|
||||||
[]reflect.Value{v(uintptr(1)), v(uintptr(2)), v(uintptr(3))},
|
|
||||||
},
|
|
||||||
// SortableStructs.
|
|
||||||
{
|
|
||||||
// Note: not sorted - DisableMethods is set.
|
|
||||||
[]reflect.Value{v(sortableStruct{2}), v(sortableStruct{1}), v(sortableStruct{3})},
|
|
||||||
[]reflect.Value{v(sortableStruct{2}), v(sortableStruct{1}), v(sortableStruct{3})},
|
|
||||||
},
|
|
||||||
// UnsortableStructs.
|
|
||||||
{
|
|
||||||
// Note: not sorted - SpewKeys is false.
|
|
||||||
[]reflect.Value{v(unsortableStruct{2}), v(unsortableStruct{1}), v(unsortableStruct{3})},
|
|
||||||
[]reflect.Value{v(unsortableStruct{2}), v(unsortableStruct{1}), v(unsortableStruct{3})},
|
|
||||||
},
|
|
||||||
// Invalid.
|
|
||||||
{
|
|
||||||
[]reflect.Value{embedB, embedA, embedC},
|
|
||||||
[]reflect.Value{embedB, embedA, embedC},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
cs := spew.ConfigState{DisableMethods: true, SpewKeys: false}
|
|
||||||
helpTestSortValues(tests, &cs, t)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestSortValuesWithMethods ensures the sort functionality for relect.Value
|
|
||||||
// based sorting works as intended when using string methods.
|
|
||||||
func TestSortValuesWithMethods(t *testing.T) {
|
|
||||||
v := reflect.ValueOf
|
|
||||||
|
|
||||||
a := v("a")
|
|
||||||
b := v("b")
|
|
||||||
c := v("c")
|
|
||||||
tests := []sortTestCase{
|
|
||||||
// Ints.
|
|
||||||
{
|
|
||||||
[]reflect.Value{v(2), v(1), v(3)},
|
|
||||||
[]reflect.Value{v(1), v(2), v(3)},
|
|
||||||
},
|
|
||||||
// Strings.
|
|
||||||
{
|
|
||||||
[]reflect.Value{b, a, c},
|
|
||||||
[]reflect.Value{a, b, c},
|
|
||||||
},
|
|
||||||
// SortableStructs.
|
|
||||||
{
|
|
||||||
[]reflect.Value{v(sortableStruct{2}), v(sortableStruct{1}), v(sortableStruct{3})},
|
|
||||||
[]reflect.Value{v(sortableStruct{1}), v(sortableStruct{2}), v(sortableStruct{3})},
|
|
||||||
},
|
|
||||||
// UnsortableStructs.
|
|
||||||
{
|
|
||||||
// Note: not sorted - SpewKeys is false.
|
|
||||||
[]reflect.Value{v(unsortableStruct{2}), v(unsortableStruct{1}), v(unsortableStruct{3})},
|
|
||||||
[]reflect.Value{v(unsortableStruct{2}), v(unsortableStruct{1}), v(unsortableStruct{3})},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
cs := spew.ConfigState{DisableMethods: false, SpewKeys: false}
|
|
||||||
helpTestSortValues(tests, &cs, t)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestSortValuesWithSpew ensures the sort functionality for relect.Value
|
|
||||||
// based sorting works as intended when using spew to stringify keys.
|
|
||||||
func TestSortValuesWithSpew(t *testing.T) {
|
|
||||||
v := reflect.ValueOf
|
|
||||||
|
|
||||||
a := v("a")
|
|
||||||
b := v("b")
|
|
||||||
c := v("c")
|
|
||||||
tests := []sortTestCase{
|
|
||||||
// Ints.
|
|
||||||
{
|
|
||||||
[]reflect.Value{v(2), v(1), v(3)},
|
|
||||||
[]reflect.Value{v(1), v(2), v(3)},
|
|
||||||
},
|
|
||||||
// Strings.
|
|
||||||
{
|
|
||||||
[]reflect.Value{b, a, c},
|
|
||||||
[]reflect.Value{a, b, c},
|
|
||||||
},
|
|
||||||
// SortableStructs.
|
|
||||||
{
|
|
||||||
[]reflect.Value{v(sortableStruct{2}), v(sortableStruct{1}), v(sortableStruct{3})},
|
|
||||||
[]reflect.Value{v(sortableStruct{1}), v(sortableStruct{2}), v(sortableStruct{3})},
|
|
||||||
},
|
|
||||||
// UnsortableStructs.
|
|
||||||
{
|
|
||||||
[]reflect.Value{v(unsortableStruct{2}), v(unsortableStruct{1}), v(unsortableStruct{3})},
|
|
||||||
[]reflect.Value{v(unsortableStruct{1}), v(unsortableStruct{2}), v(unsortableStruct{3})},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
cs := spew.ConfigState{DisableMethods: true, SpewKeys: true}
|
|
||||||
helpTestSortValues(tests, &cs, t)
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,101 +0,0 @@
|
||||||
// Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
|
|
||||||
//
|
|
||||||
// Permission to use, copy, modify, and distribute this software for any
|
|
||||||
// purpose with or without fee is hereby granted, provided that the above
|
|
||||||
// copyright notice and this permission notice appear in all copies.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
|
|
||||||
// NOTE: Due to the following build constraints, this file will only be compiled
|
|
||||||
// when both cgo is supported and "-tags testcgo" is added to the go test
|
|
||||||
// command line. This means the cgo tests are only added (and hence run) when
|
|
||||||
// specifially requested. This configuration is used because spew itself
|
|
||||||
// does not require cgo to run even though it does handle certain cgo types
|
|
||||||
// specially. Rather than forcing all clients to require cgo and an external
|
|
||||||
// C compiler just to run the tests, this scheme makes them optional.
|
|
||||||
// +build cgo,testcgo
|
|
||||||
|
|
||||||
package spew_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew/testdata"
|
|
||||||
)
|
|
||||||
|
|
||||||
func addCgoDumpTests() {
|
|
||||||
// C char pointer.
|
|
||||||
v := testdata.GetCgoCharPointer()
|
|
||||||
nv := testdata.GetCgoNullCharPointer()
|
|
||||||
pv := &v
|
|
||||||
vcAddr := fmt.Sprintf("%p", v)
|
|
||||||
vAddr := fmt.Sprintf("%p", pv)
|
|
||||||
pvAddr := fmt.Sprintf("%p", &pv)
|
|
||||||
vt := "*testdata._Ctype_char"
|
|
||||||
vs := "116"
|
|
||||||
addDumpTest(v, "("+vt+")("+vcAddr+")("+vs+")\n")
|
|
||||||
addDumpTest(pv, "(*"+vt+")("+vAddr+"->"+vcAddr+")("+vs+")\n")
|
|
||||||
addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+"->"+vcAddr+")("+vs+")\n")
|
|
||||||
addDumpTest(nv, "("+vt+")(<nil>)\n")
|
|
||||||
|
|
||||||
// C char array.
|
|
||||||
v2, v2l, v2c := testdata.GetCgoCharArray()
|
|
||||||
v2Len := fmt.Sprintf("%d", v2l)
|
|
||||||
v2Cap := fmt.Sprintf("%d", v2c)
|
|
||||||
v2t := "[6]testdata._Ctype_char"
|
|
||||||
v2s := "(len=" + v2Len + " cap=" + v2Cap + ") " +
|
|
||||||
"{\n 00000000 74 65 73 74 32 00 " +
|
|
||||||
" |test2.|\n}"
|
|
||||||
addDumpTest(v2, "("+v2t+") "+v2s+"\n")
|
|
||||||
|
|
||||||
// C unsigned char array.
|
|
||||||
v3, v3l, v3c := testdata.GetCgoUnsignedCharArray()
|
|
||||||
v3Len := fmt.Sprintf("%d", v3l)
|
|
||||||
v3Cap := fmt.Sprintf("%d", v3c)
|
|
||||||
v3t := "[6]testdata._Ctype_unsignedchar"
|
|
||||||
v3t2 := "[6]testdata._Ctype_uchar"
|
|
||||||
v3s := "(len=" + v3Len + " cap=" + v3Cap + ") " +
|
|
||||||
"{\n 00000000 74 65 73 74 33 00 " +
|
|
||||||
" |test3.|\n}"
|
|
||||||
addDumpTest(v3, "("+v3t+") "+v3s+"\n", "("+v3t2+") "+v3s+"\n")
|
|
||||||
|
|
||||||
// C signed char array.
|
|
||||||
v4, v4l, v4c := testdata.GetCgoSignedCharArray()
|
|
||||||
v4Len := fmt.Sprintf("%d", v4l)
|
|
||||||
v4Cap := fmt.Sprintf("%d", v4c)
|
|
||||||
v4t := "[6]testdata._Ctype_schar"
|
|
||||||
v4t2 := "testdata._Ctype_schar"
|
|
||||||
v4s := "(len=" + v4Len + " cap=" + v4Cap + ") " +
|
|
||||||
"{\n (" + v4t2 + ") 116,\n (" + v4t2 + ") 101,\n (" + v4t2 +
|
|
||||||
") 115,\n (" + v4t2 + ") 116,\n (" + v4t2 + ") 52,\n (" + v4t2 +
|
|
||||||
") 0\n}"
|
|
||||||
addDumpTest(v4, "("+v4t+") "+v4s+"\n")
|
|
||||||
|
|
||||||
// C uint8_t array.
|
|
||||||
v5, v5l, v5c := testdata.GetCgoUint8tArray()
|
|
||||||
v5Len := fmt.Sprintf("%d", v5l)
|
|
||||||
v5Cap := fmt.Sprintf("%d", v5c)
|
|
||||||
v5t := "[6]testdata._Ctype_uint8_t"
|
|
||||||
v5t2 := "[6]testdata._Ctype_uchar"
|
|
||||||
v5s := "(len=" + v5Len + " cap=" + v5Cap + ") " +
|
|
||||||
"{\n 00000000 74 65 73 74 35 00 " +
|
|
||||||
" |test5.|\n}"
|
|
||||||
addDumpTest(v5, "("+v5t+") "+v5s+"\n", "("+v5t2+") "+v5s+"\n")
|
|
||||||
|
|
||||||
// C typedefed unsigned char array.
|
|
||||||
v6, v6l, v6c := testdata.GetCgoTypdefedUnsignedCharArray()
|
|
||||||
v6Len := fmt.Sprintf("%d", v6l)
|
|
||||||
v6Cap := fmt.Sprintf("%d", v6c)
|
|
||||||
v6t := "[6]testdata._Ctype_custom_uchar_t"
|
|
||||||
v6t2 := "[6]testdata._Ctype_uchar"
|
|
||||||
v6s := "(len=" + v6Len + " cap=" + v6Cap + ") " +
|
|
||||||
"{\n 00000000 74 65 73 74 36 00 " +
|
|
||||||
" |test6.|\n}"
|
|
||||||
addDumpTest(v6, "("+v6t+") "+v6s+"\n", "("+v6t2+") "+v6s+"\n")
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
// Copyright (c) 2013 Dave Collins <dave@davec.name>
|
|
||||||
//
|
|
||||||
// Permission to use, copy, modify, and distribute this software for any
|
|
||||||
// purpose with or without fee is hereby granted, provided that the above
|
|
||||||
// copyright notice and this permission notice appear in all copies.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
|
|
||||||
// NOTE: Due to the following build constraints, this file will only be compiled
|
|
||||||
// when either cgo is not supported or "-tags testcgo" is not added to the go
|
|
||||||
// test command line. This file intentionally does not setup any cgo tests in
|
|
||||||
// this scenario.
|
|
||||||
// +build !cgo !testcgo
|
|
||||||
|
|
||||||
package spew_test
|
|
||||||
|
|
||||||
func addCgoDumpTests() {
|
|
||||||
// Don't add any tests for cgo since this file is only compiled when
|
|
||||||
// there should not be any cgo tests.
|
|
||||||
}
|
|
|
@ -1,226 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package spew_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Flag int
|
|
||||||
|
|
||||||
const (
|
|
||||||
flagOne Flag = iota
|
|
||||||
flagTwo
|
|
||||||
)
|
|
||||||
|
|
||||||
var flagStrings = map[Flag]string{
|
|
||||||
flagOne: "flagOne",
|
|
||||||
flagTwo: "flagTwo",
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f Flag) String() string {
|
|
||||||
if s, ok := flagStrings[f]; ok {
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("Unknown flag (%d)", int(f))
|
|
||||||
}
|
|
||||||
|
|
||||||
type Bar struct {
|
|
||||||
data uintptr
|
|
||||||
}
|
|
||||||
|
|
||||||
type Foo struct {
|
|
||||||
unexportedField Bar
|
|
||||||
ExportedField map[interface{}]interface{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This example demonstrates how to use Dump to dump variables to stdout.
|
|
||||||
func ExampleDump() {
|
|
||||||
// The following package level declarations are assumed for this example:
|
|
||||||
/*
|
|
||||||
type Flag int
|
|
||||||
|
|
||||||
const (
|
|
||||||
flagOne Flag = iota
|
|
||||||
flagTwo
|
|
||||||
)
|
|
||||||
|
|
||||||
var flagStrings = map[Flag]string{
|
|
||||||
flagOne: "flagOne",
|
|
||||||
flagTwo: "flagTwo",
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f Flag) String() string {
|
|
||||||
if s, ok := flagStrings[f]; ok {
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("Unknown flag (%d)", int(f))
|
|
||||||
}
|
|
||||||
|
|
||||||
type Bar struct {
|
|
||||||
data uintptr
|
|
||||||
}
|
|
||||||
|
|
||||||
type Foo struct {
|
|
||||||
unexportedField Bar
|
|
||||||
ExportedField map[interface{}]interface{}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Setup some sample data structures for the example.
|
|
||||||
bar := Bar{uintptr(0)}
|
|
||||||
s1 := Foo{bar, map[interface{}]interface{}{"one": true}}
|
|
||||||
f := Flag(5)
|
|
||||||
b := []byte{
|
|
||||||
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
|
|
||||||
0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
|
|
||||||
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
|
|
||||||
0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
|
|
||||||
0x31, 0x32,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dump!
|
|
||||||
spew.Dump(s1, f, b)
|
|
||||||
|
|
||||||
// Output:
|
|
||||||
// (spew_test.Foo) {
|
|
||||||
// unexportedField: (spew_test.Bar) {
|
|
||||||
// data: (uintptr) <nil>
|
|
||||||
// },
|
|
||||||
// ExportedField: (map[interface {}]interface {}) (len=1) {
|
|
||||||
// (string) (len=3) "one": (bool) true
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// (spew_test.Flag) Unknown flag (5)
|
|
||||||
// ([]uint8) (len=34 cap=34) {
|
|
||||||
// 00000000 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 |............... |
|
|
||||||
// 00000010 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 |!"#$%&'()*+,-./0|
|
|
||||||
// 00000020 31 32 |12|
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
// This example demonstrates how to use Printf to display a variable with a
|
|
||||||
// format string and inline formatting.
|
|
||||||
func ExamplePrintf() {
|
|
||||||
// Create a double pointer to a uint 8.
|
|
||||||
ui8 := uint8(5)
|
|
||||||
pui8 := &ui8
|
|
||||||
ppui8 := &pui8
|
|
||||||
|
|
||||||
// Create a circular data type.
|
|
||||||
type circular struct {
|
|
||||||
ui8 uint8
|
|
||||||
c *circular
|
|
||||||
}
|
|
||||||
c := circular{ui8: 1}
|
|
||||||
c.c = &c
|
|
||||||
|
|
||||||
// Print!
|
|
||||||
spew.Printf("ppui8: %v\n", ppui8)
|
|
||||||
spew.Printf("circular: %v\n", c)
|
|
||||||
|
|
||||||
// Output:
|
|
||||||
// ppui8: <**>5
|
|
||||||
// circular: {1 <*>{1 <*><shown>}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This example demonstrates how to use a ConfigState.
|
|
||||||
func ExampleConfigState() {
|
|
||||||
// Modify the indent level of the ConfigState only. The global
|
|
||||||
// configuration is not modified.
|
|
||||||
scs := spew.ConfigState{Indent: "\t"}
|
|
||||||
|
|
||||||
// Output using the ConfigState instance.
|
|
||||||
v := map[string]int{"one": 1}
|
|
||||||
scs.Printf("v: %v\n", v)
|
|
||||||
scs.Dump(v)
|
|
||||||
|
|
||||||
// Output:
|
|
||||||
// v: map[one:1]
|
|
||||||
// (map[string]int) (len=1) {
|
|
||||||
// (string) (len=3) "one": (int) 1
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
// This example demonstrates how to use ConfigState.Dump to dump variables to
|
|
||||||
// stdout
|
|
||||||
func ExampleConfigState_Dump() {
|
|
||||||
// See the top-level Dump example for details on the types used in this
|
|
||||||
// example.
|
|
||||||
|
|
||||||
// Create two ConfigState instances with different indentation.
|
|
||||||
scs := spew.ConfigState{Indent: "\t"}
|
|
||||||
scs2 := spew.ConfigState{Indent: " "}
|
|
||||||
|
|
||||||
// Setup some sample data structures for the example.
|
|
||||||
bar := Bar{uintptr(0)}
|
|
||||||
s1 := Foo{bar, map[interface{}]interface{}{"one": true}}
|
|
||||||
|
|
||||||
// Dump using the ConfigState instances.
|
|
||||||
scs.Dump(s1)
|
|
||||||
scs2.Dump(s1)
|
|
||||||
|
|
||||||
// Output:
|
|
||||||
// (spew_test.Foo) {
|
|
||||||
// unexportedField: (spew_test.Bar) {
|
|
||||||
// data: (uintptr) <nil>
|
|
||||||
// },
|
|
||||||
// ExportedField: (map[interface {}]interface {}) (len=1) {
|
|
||||||
// (string) (len=3) "one": (bool) true
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// (spew_test.Foo) {
|
|
||||||
// unexportedField: (spew_test.Bar) {
|
|
||||||
// data: (uintptr) <nil>
|
|
||||||
// },
|
|
||||||
// ExportedField: (map[interface {}]interface {}) (len=1) {
|
|
||||||
// (string) (len=3) "one": (bool) true
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
// This example demonstrates how to use ConfigState.Printf to display a variable
|
|
||||||
// with a format string and inline formatting.
|
|
||||||
func ExampleConfigState_Printf() {
|
|
||||||
// See the top-level Dump example for details on the types used in this
|
|
||||||
// example.
|
|
||||||
|
|
||||||
// Create two ConfigState instances and modify the method handling of the
|
|
||||||
// first ConfigState only.
|
|
||||||
scs := spew.NewDefaultConfig()
|
|
||||||
scs2 := spew.NewDefaultConfig()
|
|
||||||
scs.DisableMethods = true
|
|
||||||
|
|
||||||
// Alternatively
|
|
||||||
// scs := spew.ConfigState{Indent: " ", DisableMethods: true}
|
|
||||||
// scs2 := spew.ConfigState{Indent: " "}
|
|
||||||
|
|
||||||
// This is of type Flag which implements a Stringer and has raw value 1.
|
|
||||||
f := flagTwo
|
|
||||||
|
|
||||||
// Dump using the ConfigState instances.
|
|
||||||
scs.Printf("f: %v\n", f)
|
|
||||||
scs2.Printf("f: %v\n", f)
|
|
||||||
|
|
||||||
// Output:
|
|
||||||
// f: 1
|
|
||||||
// f: flagTwo
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,84 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
This test file is part of the spew package rather than than the spew_test
|
|
||||||
package because it needs access to internals to properly test certain cases
|
|
||||||
which are not possible via the public interface since they should never happen.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package spew
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
// dummyFmtState implements a fake fmt.State to use for testing invalid
|
|
||||||
// reflect.Value handling. This is necessary because the fmt package catches
|
|
||||||
// invalid values before invoking the formatter on them.
|
|
||||||
type dummyFmtState struct {
|
|
||||||
bytes.Buffer
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dfs *dummyFmtState) Flag(f int) bool {
|
|
||||||
return f == int('+')
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dfs *dummyFmtState) Precision() (int, bool) {
|
|
||||||
return 0, false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dfs *dummyFmtState) Width() (int, bool) {
|
|
||||||
return 0, false
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestInvalidReflectValue ensures the dump and formatter code handles an
|
|
||||||
// invalid reflect value properly. This needs access to internal state since it
|
|
||||||
// should never happen in real code and therefore can't be tested via the public
|
|
||||||
// API.
|
|
||||||
func TestInvalidReflectValue(t *testing.T) {
|
|
||||||
i := 1
|
|
||||||
|
|
||||||
// Dump invalid reflect value.
|
|
||||||
v := new(reflect.Value)
|
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
d := dumpState{w: buf, cs: &Config}
|
|
||||||
d.dump(*v)
|
|
||||||
s := buf.String()
|
|
||||||
want := "<invalid>"
|
|
||||||
if s != want {
|
|
||||||
t.Errorf("InvalidReflectValue #%d\n got: %s want: %s", i, s, want)
|
|
||||||
}
|
|
||||||
i++
|
|
||||||
|
|
||||||
// Formatter invalid reflect value.
|
|
||||||
buf2 := new(dummyFmtState)
|
|
||||||
f := formatState{value: *v, cs: &Config, fs: buf2}
|
|
||||||
f.format(*v)
|
|
||||||
s = buf2.String()
|
|
||||||
want = "<invalid>"
|
|
||||||
if s != want {
|
|
||||||
t.Errorf("InvalidReflectValue #%d got: %s want: %s", i, s, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SortValues makes the internal sortValues function available to the test
|
|
||||||
// package.
|
|
||||||
func SortValues(values []reflect.Value, cs *ConfigState) {
|
|
||||||
sortValues(values, cs)
|
|
||||||
}
|
|
|
@ -1,101 +0,0 @@
|
||||||
// Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
|
|
||||||
|
|
||||||
// Permission to use, copy, modify, and distribute this software for any
|
|
||||||
// purpose with or without fee is hereby granted, provided that the above
|
|
||||||
// copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
|
|
||||||
// NOTE: Due to the following build constraints, this file will only be compiled
|
|
||||||
// when the code is not running on Google App Engine, compiled by GopherJS, and
|
|
||||||
// "-tags safe" is not added to the go build command line. The "disableunsafe"
|
|
||||||
// tag is deprecated and thus should not be used.
|
|
||||||
// +build !js,!appengine,!safe,!disableunsafe,go1.4
|
|
||||||
|
|
||||||
/*
|
|
||||||
This test file is part of the spew package rather than than the spew_test
|
|
||||||
package because it needs access to internals to properly test certain cases
|
|
||||||
which are not possible via the public interface since they should never happen.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package spew
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
// changeKind uses unsafe to intentionally change the kind of a reflect.Value to
|
|
||||||
// the maximum kind value which does not exist. This is needed to test the
|
|
||||||
// fallback code which punts to the standard fmt library for new types that
|
|
||||||
// might get added to the language.
|
|
||||||
func changeKind(v *reflect.Value, readOnly bool) {
|
|
||||||
flags := flagField(v)
|
|
||||||
if readOnly {
|
|
||||||
*flags |= flagRO
|
|
||||||
} else {
|
|
||||||
*flags &^= flagRO
|
|
||||||
}
|
|
||||||
*flags |= flagKindMask
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestAddedReflectValue tests functionaly of the dump and formatter code which
|
|
||||||
// falls back to the standard fmt library for new types that might get added to
|
|
||||||
// the language.
|
|
||||||
func TestAddedReflectValue(t *testing.T) {
|
|
||||||
i := 1
|
|
||||||
|
|
||||||
// Dump using a reflect.Value that is exported.
|
|
||||||
v := reflect.ValueOf(int8(5))
|
|
||||||
changeKind(&v, false)
|
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
d := dumpState{w: buf, cs: &Config}
|
|
||||||
d.dump(v)
|
|
||||||
s := buf.String()
|
|
||||||
want := "(int8) 5"
|
|
||||||
if s != want {
|
|
||||||
t.Errorf("TestAddedReflectValue #%d\n got: %s want: %s", i, s, want)
|
|
||||||
}
|
|
||||||
i++
|
|
||||||
|
|
||||||
// Dump using a reflect.Value that is not exported.
|
|
||||||
changeKind(&v, true)
|
|
||||||
buf.Reset()
|
|
||||||
d.dump(v)
|
|
||||||
s = buf.String()
|
|
||||||
want = "(int8) <int8 Value>"
|
|
||||||
if s != want {
|
|
||||||
t.Errorf("TestAddedReflectValue #%d\n got: %s want: %s", i, s, want)
|
|
||||||
}
|
|
||||||
i++
|
|
||||||
|
|
||||||
// Formatter using a reflect.Value that is exported.
|
|
||||||
changeKind(&v, false)
|
|
||||||
buf2 := new(dummyFmtState)
|
|
||||||
f := formatState{value: v, cs: &Config, fs: buf2}
|
|
||||||
f.format(v)
|
|
||||||
s = buf2.String()
|
|
||||||
want = "5"
|
|
||||||
if s != want {
|
|
||||||
t.Errorf("TestAddedReflectValue #%d got: %s want: %s", i, s, want)
|
|
||||||
}
|
|
||||||
i++
|
|
||||||
|
|
||||||
// Formatter using a reflect.Value that is not exported.
|
|
||||||
changeKind(&v, true)
|
|
||||||
buf2.Reset()
|
|
||||||
f = formatState{value: v, cs: &Config, fs: buf2}
|
|
||||||
f.format(v)
|
|
||||||
s = buf2.String()
|
|
||||||
want = "<int8 Value>"
|
|
||||||
if s != want {
|
|
||||||
t.Errorf("TestAddedReflectValue #%d got: %s want: %s", i, s, want)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,320 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package spew_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
|
||||||
)
|
|
||||||
|
|
||||||
// spewFunc is used to identify which public function of the spew package or
|
|
||||||
// ConfigState a test applies to.
|
|
||||||
type spewFunc int
|
|
||||||
|
|
||||||
const (
|
|
||||||
fCSFdump spewFunc = iota
|
|
||||||
fCSFprint
|
|
||||||
fCSFprintf
|
|
||||||
fCSFprintln
|
|
||||||
fCSPrint
|
|
||||||
fCSPrintln
|
|
||||||
fCSSdump
|
|
||||||
fCSSprint
|
|
||||||
fCSSprintf
|
|
||||||
fCSSprintln
|
|
||||||
fCSErrorf
|
|
||||||
fCSNewFormatter
|
|
||||||
fErrorf
|
|
||||||
fFprint
|
|
||||||
fFprintln
|
|
||||||
fPrint
|
|
||||||
fPrintln
|
|
||||||
fSdump
|
|
||||||
fSprint
|
|
||||||
fSprintf
|
|
||||||
fSprintln
|
|
||||||
)
|
|
||||||
|
|
||||||
// Map of spewFunc values to names for pretty printing.
|
|
||||||
var spewFuncStrings = map[spewFunc]string{
|
|
||||||
fCSFdump: "ConfigState.Fdump",
|
|
||||||
fCSFprint: "ConfigState.Fprint",
|
|
||||||
fCSFprintf: "ConfigState.Fprintf",
|
|
||||||
fCSFprintln: "ConfigState.Fprintln",
|
|
||||||
fCSSdump: "ConfigState.Sdump",
|
|
||||||
fCSPrint: "ConfigState.Print",
|
|
||||||
fCSPrintln: "ConfigState.Println",
|
|
||||||
fCSSprint: "ConfigState.Sprint",
|
|
||||||
fCSSprintf: "ConfigState.Sprintf",
|
|
||||||
fCSSprintln: "ConfigState.Sprintln",
|
|
||||||
fCSErrorf: "ConfigState.Errorf",
|
|
||||||
fCSNewFormatter: "ConfigState.NewFormatter",
|
|
||||||
fErrorf: "spew.Errorf",
|
|
||||||
fFprint: "spew.Fprint",
|
|
||||||
fFprintln: "spew.Fprintln",
|
|
||||||
fPrint: "spew.Print",
|
|
||||||
fPrintln: "spew.Println",
|
|
||||||
fSdump: "spew.Sdump",
|
|
||||||
fSprint: "spew.Sprint",
|
|
||||||
fSprintf: "spew.Sprintf",
|
|
||||||
fSprintln: "spew.Sprintln",
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f spewFunc) String() string {
|
|
||||||
if s, ok := spewFuncStrings[f]; ok {
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("Unknown spewFunc (%d)", int(f))
|
|
||||||
}
|
|
||||||
|
|
||||||
// spewTest is used to describe a test to be performed against the public
|
|
||||||
// functions of the spew package or ConfigState.
|
|
||||||
type spewTest struct {
|
|
||||||
cs *spew.ConfigState
|
|
||||||
f spewFunc
|
|
||||||
format string
|
|
||||||
in interface{}
|
|
||||||
want string
|
|
||||||
}
|
|
||||||
|
|
||||||
// spewTests houses the tests to be performed against the public functions of
|
|
||||||
// the spew package and ConfigState.
|
|
||||||
//
|
|
||||||
// These tests are only intended to ensure the public functions are exercised
|
|
||||||
// and are intentionally not exhaustive of types. The exhaustive type
|
|
||||||
// tests are handled in the dump and format tests.
|
|
||||||
var spewTests []spewTest
|
|
||||||
|
|
||||||
// redirStdout is a helper function to return the standard output from f as a
|
|
||||||
// byte slice.
|
|
||||||
func redirStdout(f func()) ([]byte, error) {
|
|
||||||
tempFile, err := ioutil.TempFile("", "ss-test")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
fileName := tempFile.Name()
|
|
||||||
defer os.Remove(fileName) // Ignore error
|
|
||||||
|
|
||||||
origStdout := os.Stdout
|
|
||||||
os.Stdout = tempFile
|
|
||||||
f()
|
|
||||||
os.Stdout = origStdout
|
|
||||||
tempFile.Close()
|
|
||||||
|
|
||||||
return ioutil.ReadFile(fileName)
|
|
||||||
}
|
|
||||||
|
|
||||||
func initSpewTests() {
|
|
||||||
// Config states with various settings.
|
|
||||||
scsDefault := spew.NewDefaultConfig()
|
|
||||||
scsNoMethods := &spew.ConfigState{Indent: " ", DisableMethods: true}
|
|
||||||
scsNoPmethods := &spew.ConfigState{Indent: " ", DisablePointerMethods: true}
|
|
||||||
scsMaxDepth := &spew.ConfigState{Indent: " ", MaxDepth: 1}
|
|
||||||
scsContinue := &spew.ConfigState{Indent: " ", ContinueOnMethod: true}
|
|
||||||
scsNoPtrAddr := &spew.ConfigState{DisablePointerAddresses: true}
|
|
||||||
scsNoCap := &spew.ConfigState{DisableCapacities: true}
|
|
||||||
|
|
||||||
// Variables for tests on types which implement Stringer interface with and
|
|
||||||
// without a pointer receiver.
|
|
||||||
ts := stringer("test")
|
|
||||||
tps := pstringer("test")
|
|
||||||
|
|
||||||
type ptrTester struct {
|
|
||||||
s *struct{}
|
|
||||||
}
|
|
||||||
tptr := &ptrTester{s: &struct{}{}}
|
|
||||||
|
|
||||||
// depthTester is used to test max depth handling for structs, array, slices
|
|
||||||
// and maps.
|
|
||||||
type depthTester struct {
|
|
||||||
ic indirCir1
|
|
||||||
arr [1]string
|
|
||||||
slice []string
|
|
||||||
m map[string]int
|
|
||||||
}
|
|
||||||
dt := depthTester{indirCir1{nil}, [1]string{"arr"}, []string{"slice"},
|
|
||||||
map[string]int{"one": 1}}
|
|
||||||
|
|
||||||
// Variable for tests on types which implement error interface.
|
|
||||||
te := customError(10)
|
|
||||||
|
|
||||||
spewTests = []spewTest{
|
|
||||||
{scsDefault, fCSFdump, "", int8(127), "(int8) 127\n"},
|
|
||||||
{scsDefault, fCSFprint, "", int16(32767), "32767"},
|
|
||||||
{scsDefault, fCSFprintf, "%v", int32(2147483647), "2147483647"},
|
|
||||||
{scsDefault, fCSFprintln, "", int(2147483647), "2147483647\n"},
|
|
||||||
{scsDefault, fCSPrint, "", int64(9223372036854775807), "9223372036854775807"},
|
|
||||||
{scsDefault, fCSPrintln, "", uint8(255), "255\n"},
|
|
||||||
{scsDefault, fCSSdump, "", uint8(64), "(uint8) 64\n"},
|
|
||||||
{scsDefault, fCSSprint, "", complex(1, 2), "(1+2i)"},
|
|
||||||
{scsDefault, fCSSprintf, "%v", complex(float32(3), 4), "(3+4i)"},
|
|
||||||
{scsDefault, fCSSprintln, "", complex(float64(5), 6), "(5+6i)\n"},
|
|
||||||
{scsDefault, fCSErrorf, "%#v", uint16(65535), "(uint16)65535"},
|
|
||||||
{scsDefault, fCSNewFormatter, "%v", uint32(4294967295), "4294967295"},
|
|
||||||
{scsDefault, fErrorf, "%v", uint64(18446744073709551615), "18446744073709551615"},
|
|
||||||
{scsDefault, fFprint, "", float32(3.14), "3.14"},
|
|
||||||
{scsDefault, fFprintln, "", float64(6.28), "6.28\n"},
|
|
||||||
{scsDefault, fPrint, "", true, "true"},
|
|
||||||
{scsDefault, fPrintln, "", false, "false\n"},
|
|
||||||
{scsDefault, fSdump, "", complex(-10, -20), "(complex128) (-10-20i)\n"},
|
|
||||||
{scsDefault, fSprint, "", complex(-1, -2), "(-1-2i)"},
|
|
||||||
{scsDefault, fSprintf, "%v", complex(float32(-3), -4), "(-3-4i)"},
|
|
||||||
{scsDefault, fSprintln, "", complex(float64(-5), -6), "(-5-6i)\n"},
|
|
||||||
{scsNoMethods, fCSFprint, "", ts, "test"},
|
|
||||||
{scsNoMethods, fCSFprint, "", &ts, "<*>test"},
|
|
||||||
{scsNoMethods, fCSFprint, "", tps, "test"},
|
|
||||||
{scsNoMethods, fCSFprint, "", &tps, "<*>test"},
|
|
||||||
{scsNoPmethods, fCSFprint, "", ts, "stringer test"},
|
|
||||||
{scsNoPmethods, fCSFprint, "", &ts, "<*>stringer test"},
|
|
||||||
{scsNoPmethods, fCSFprint, "", tps, "test"},
|
|
||||||
{scsNoPmethods, fCSFprint, "", &tps, "<*>stringer test"},
|
|
||||||
{scsMaxDepth, fCSFprint, "", dt, "{{<max>} [<max>] [<max>] map[<max>]}"},
|
|
||||||
{scsMaxDepth, fCSFdump, "", dt, "(spew_test.depthTester) {\n" +
|
|
||||||
" ic: (spew_test.indirCir1) {\n <max depth reached>\n },\n" +
|
|
||||||
" arr: ([1]string) (len=1 cap=1) {\n <max depth reached>\n },\n" +
|
|
||||||
" slice: ([]string) (len=1 cap=1) {\n <max depth reached>\n },\n" +
|
|
||||||
" m: (map[string]int) (len=1) {\n <max depth reached>\n }\n}\n"},
|
|
||||||
{scsContinue, fCSFprint, "", ts, "(stringer test) test"},
|
|
||||||
{scsContinue, fCSFdump, "", ts, "(spew_test.stringer) " +
|
|
||||||
"(len=4) (stringer test) \"test\"\n"},
|
|
||||||
{scsContinue, fCSFprint, "", te, "(error: 10) 10"},
|
|
||||||
{scsContinue, fCSFdump, "", te, "(spew_test.customError) " +
|
|
||||||
"(error: 10) 10\n"},
|
|
||||||
{scsNoPtrAddr, fCSFprint, "", tptr, "<*>{<*>{}}"},
|
|
||||||
{scsNoPtrAddr, fCSSdump, "", tptr, "(*spew_test.ptrTester)({\ns: (*struct {})({\n})\n})\n"},
|
|
||||||
{scsNoCap, fCSSdump, "", make([]string, 0, 10), "([]string) {\n}\n"},
|
|
||||||
{scsNoCap, fCSSdump, "", make([]string, 1, 10), "([]string) (len=1) {\n(string) \"\"\n}\n"},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestSpew executes all of the tests described by spewTests.
|
|
||||||
func TestSpew(t *testing.T) {
|
|
||||||
initSpewTests()
|
|
||||||
|
|
||||||
t.Logf("Running %d tests", len(spewTests))
|
|
||||||
for i, test := range spewTests {
|
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
switch test.f {
|
|
||||||
case fCSFdump:
|
|
||||||
test.cs.Fdump(buf, test.in)
|
|
||||||
|
|
||||||
case fCSFprint:
|
|
||||||
test.cs.Fprint(buf, test.in)
|
|
||||||
|
|
||||||
case fCSFprintf:
|
|
||||||
test.cs.Fprintf(buf, test.format, test.in)
|
|
||||||
|
|
||||||
case fCSFprintln:
|
|
||||||
test.cs.Fprintln(buf, test.in)
|
|
||||||
|
|
||||||
case fCSPrint:
|
|
||||||
b, err := redirStdout(func() { test.cs.Print(test.in) })
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("%v #%d %v", test.f, i, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
buf.Write(b)
|
|
||||||
|
|
||||||
case fCSPrintln:
|
|
||||||
b, err := redirStdout(func() { test.cs.Println(test.in) })
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("%v #%d %v", test.f, i, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
buf.Write(b)
|
|
||||||
|
|
||||||
case fCSSdump:
|
|
||||||
str := test.cs.Sdump(test.in)
|
|
||||||
buf.WriteString(str)
|
|
||||||
|
|
||||||
case fCSSprint:
|
|
||||||
str := test.cs.Sprint(test.in)
|
|
||||||
buf.WriteString(str)
|
|
||||||
|
|
||||||
case fCSSprintf:
|
|
||||||
str := test.cs.Sprintf(test.format, test.in)
|
|
||||||
buf.WriteString(str)
|
|
||||||
|
|
||||||
case fCSSprintln:
|
|
||||||
str := test.cs.Sprintln(test.in)
|
|
||||||
buf.WriteString(str)
|
|
||||||
|
|
||||||
case fCSErrorf:
|
|
||||||
err := test.cs.Errorf(test.format, test.in)
|
|
||||||
buf.WriteString(err.Error())
|
|
||||||
|
|
||||||
case fCSNewFormatter:
|
|
||||||
fmt.Fprintf(buf, test.format, test.cs.NewFormatter(test.in))
|
|
||||||
|
|
||||||
case fErrorf:
|
|
||||||
err := spew.Errorf(test.format, test.in)
|
|
||||||
buf.WriteString(err.Error())
|
|
||||||
|
|
||||||
case fFprint:
|
|
||||||
spew.Fprint(buf, test.in)
|
|
||||||
|
|
||||||
case fFprintln:
|
|
||||||
spew.Fprintln(buf, test.in)
|
|
||||||
|
|
||||||
case fPrint:
|
|
||||||
b, err := redirStdout(func() { spew.Print(test.in) })
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("%v #%d %v", test.f, i, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
buf.Write(b)
|
|
||||||
|
|
||||||
case fPrintln:
|
|
||||||
b, err := redirStdout(func() { spew.Println(test.in) })
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("%v #%d %v", test.f, i, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
buf.Write(b)
|
|
||||||
|
|
||||||
case fSdump:
|
|
||||||
str := spew.Sdump(test.in)
|
|
||||||
buf.WriteString(str)
|
|
||||||
|
|
||||||
case fSprint:
|
|
||||||
str := spew.Sprint(test.in)
|
|
||||||
buf.WriteString(str)
|
|
||||||
|
|
||||||
case fSprintf:
|
|
||||||
str := spew.Sprintf(test.format, test.in)
|
|
||||||
buf.WriteString(str)
|
|
||||||
|
|
||||||
case fSprintln:
|
|
||||||
str := spew.Sprintln(test.in)
|
|
||||||
buf.WriteString(str)
|
|
||||||
|
|
||||||
default:
|
|
||||||
t.Errorf("%v #%d unrecognized function", test.f, i)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
s := buf.String()
|
|
||||||
if test.want != s {
|
|
||||||
t.Errorf("ConfigState #%d\n got: %s want: %s", i, s, test.want)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,82 +0,0 @@
|
||||||
// Copyright (c) 2013 Dave Collins <dave@davec.name>
|
|
||||||
//
|
|
||||||
// Permission to use, copy, modify, and distribute this software for any
|
|
||||||
// purpose with or without fee is hereby granted, provided that the above
|
|
||||||
// copyright notice and this permission notice appear in all copies.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
|
|
||||||
// NOTE: Due to the following build constraints, this file will only be compiled
|
|
||||||
// when both cgo is supported and "-tags testcgo" is added to the go test
|
|
||||||
// command line. This code should really only be in the dumpcgo_test.go file,
|
|
||||||
// but unfortunately Go will not allow cgo in test files, so this is a
|
|
||||||
// workaround to allow cgo types to be tested. This configuration is used
|
|
||||||
// because spew itself does not require cgo to run even though it does handle
|
|
||||||
// certain cgo types specially. Rather than forcing all clients to require cgo
|
|
||||||
// and an external C compiler just to run the tests, this scheme makes them
|
|
||||||
// optional.
|
|
||||||
// +build cgo,testcgo
|
|
||||||
|
|
||||||
package testdata
|
|
||||||
|
|
||||||
/*
|
|
||||||
#include <stdint.h>
|
|
||||||
typedef unsigned char custom_uchar_t;
|
|
||||||
|
|
||||||
char *ncp = 0;
|
|
||||||
char *cp = "test";
|
|
||||||
char ca[6] = {'t', 'e', 's', 't', '2', '\0'};
|
|
||||||
unsigned char uca[6] = {'t', 'e', 's', 't', '3', '\0'};
|
|
||||||
signed char sca[6] = {'t', 'e', 's', 't', '4', '\0'};
|
|
||||||
uint8_t ui8ta[6] = {'t', 'e', 's', 't', '5', '\0'};
|
|
||||||
custom_uchar_t tuca[6] = {'t', 'e', 's', 't', '6', '\0'};
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
// GetCgoNullCharPointer returns a null char pointer via cgo. This is only
|
|
||||||
// used for tests.
|
|
||||||
func GetCgoNullCharPointer() interface{} {
|
|
||||||
return C.ncp
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCgoCharPointer returns a char pointer via cgo. This is only used for
|
|
||||||
// tests.
|
|
||||||
func GetCgoCharPointer() interface{} {
|
|
||||||
return C.cp
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCgoCharArray returns a char array via cgo and the array's len and cap.
|
|
||||||
// This is only used for tests.
|
|
||||||
func GetCgoCharArray() (interface{}, int, int) {
|
|
||||||
return C.ca, len(C.ca), cap(C.ca)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCgoUnsignedCharArray returns an unsigned char array via cgo and the
|
|
||||||
// array's len and cap. This is only used for tests.
|
|
||||||
func GetCgoUnsignedCharArray() (interface{}, int, int) {
|
|
||||||
return C.uca, len(C.uca), cap(C.uca)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCgoSignedCharArray returns a signed char array via cgo and the array's len
|
|
||||||
// and cap. This is only used for tests.
|
|
||||||
func GetCgoSignedCharArray() (interface{}, int, int) {
|
|
||||||
return C.sca, len(C.sca), cap(C.sca)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCgoUint8tArray returns a uint8_t array via cgo and the array's len and
|
|
||||||
// cap. This is only used for tests.
|
|
||||||
func GetCgoUint8tArray() (interface{}, int, int) {
|
|
||||||
return C.ui8ta, len(C.ui8ta), cap(C.ui8ta)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCgoTypdefedUnsignedCharArray returns a typedefed unsigned char array via
|
|
||||||
// cgo and the array's len and cap. This is only used for tests.
|
|
||||||
func GetCgoTypdefedUnsignedCharArray() (interface{}, int, int) {
|
|
||||||
return C.tuca, len(C.tuca), cap(C.tuca)
|
|
||||||
}
|
|
|
@ -1,61 +0,0 @@
|
||||||
|
|
||||||
github.com/davecgh/go-spew/spew/dump.go dumpState.dump 100.00% (88/88)
|
|
||||||
github.com/davecgh/go-spew/spew/format.go formatState.format 100.00% (82/82)
|
|
||||||
github.com/davecgh/go-spew/spew/format.go formatState.formatPtr 100.00% (52/52)
|
|
||||||
github.com/davecgh/go-spew/spew/dump.go dumpState.dumpPtr 100.00% (44/44)
|
|
||||||
github.com/davecgh/go-spew/spew/dump.go dumpState.dumpSlice 100.00% (39/39)
|
|
||||||
github.com/davecgh/go-spew/spew/common.go handleMethods 100.00% (30/30)
|
|
||||||
github.com/davecgh/go-spew/spew/common.go printHexPtr 100.00% (18/18)
|
|
||||||
github.com/davecgh/go-spew/spew/common.go unsafeReflectValue 100.00% (13/13)
|
|
||||||
github.com/davecgh/go-spew/spew/format.go formatState.constructOrigFormat 100.00% (12/12)
|
|
||||||
github.com/davecgh/go-spew/spew/dump.go fdump 100.00% (11/11)
|
|
||||||
github.com/davecgh/go-spew/spew/format.go formatState.Format 100.00% (11/11)
|
|
||||||
github.com/davecgh/go-spew/spew/common.go init 100.00% (10/10)
|
|
||||||
github.com/davecgh/go-spew/spew/common.go printComplex 100.00% (9/9)
|
|
||||||
github.com/davecgh/go-spew/spew/common.go valuesSorter.Less 100.00% (8/8)
|
|
||||||
github.com/davecgh/go-spew/spew/format.go formatState.buildDefaultFormat 100.00% (7/7)
|
|
||||||
github.com/davecgh/go-spew/spew/format.go formatState.unpackValue 100.00% (5/5)
|
|
||||||
github.com/davecgh/go-spew/spew/dump.go dumpState.indent 100.00% (4/4)
|
|
||||||
github.com/davecgh/go-spew/spew/common.go catchPanic 100.00% (4/4)
|
|
||||||
github.com/davecgh/go-spew/spew/config.go ConfigState.convertArgs 100.00% (4/4)
|
|
||||||
github.com/davecgh/go-spew/spew/spew.go convertArgs 100.00% (4/4)
|
|
||||||
github.com/davecgh/go-spew/spew/format.go newFormatter 100.00% (3/3)
|
|
||||||
github.com/davecgh/go-spew/spew/dump.go Sdump 100.00% (3/3)
|
|
||||||
github.com/davecgh/go-spew/spew/common.go printBool 100.00% (3/3)
|
|
||||||
github.com/davecgh/go-spew/spew/common.go sortValues 100.00% (3/3)
|
|
||||||
github.com/davecgh/go-spew/spew/config.go ConfigState.Sdump 100.00% (3/3)
|
|
||||||
github.com/davecgh/go-spew/spew/dump.go dumpState.unpackValue 100.00% (3/3)
|
|
||||||
github.com/davecgh/go-spew/spew/spew.go Printf 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/spew.go Println 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/spew.go Sprint 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/spew.go Sprintf 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/spew.go Sprintln 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/common.go printFloat 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/config.go NewDefaultConfig 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/common.go printInt 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/common.go printUint 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/common.go valuesSorter.Len 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/common.go valuesSorter.Swap 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/config.go ConfigState.Errorf 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/config.go ConfigState.Fprint 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/config.go ConfigState.Fprintf 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/config.go ConfigState.Fprintln 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/config.go ConfigState.Print 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/config.go ConfigState.Printf 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/config.go ConfigState.Println 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/config.go ConfigState.Sprint 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/config.go ConfigState.Sprintf 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/config.go ConfigState.Sprintln 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/config.go ConfigState.NewFormatter 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/config.go ConfigState.Fdump 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/config.go ConfigState.Dump 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/dump.go Fdump 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/dump.go Dump 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/spew.go Fprintln 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/format.go NewFormatter 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/spew.go Errorf 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/spew.go Fprint 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/spew.go Fprintf 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew/spew.go Print 100.00% (1/1)
|
|
||||||
github.com/davecgh/go-spew/spew ------------------------------- 100.00% (505/505)
|
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
sudo: false
|
|
||||||
addons:
|
|
||||||
apt_packages:
|
|
||||||
- libgles2-mesa-dev
|
|
||||||
language: go
|
|
||||||
go:
|
|
||||||
- 1.8.x
|
|
||||||
- 1.4.x
|
|
||||||
- master
|
|
||||||
matrix:
|
|
||||||
allow_failures:
|
|
||||||
- go: master
|
|
||||||
fast_finish: true
|
|
||||||
install:
|
|
||||||
- # Do nothing. This is needed to prevent default install action "go get -t -v ./..." from happening here (we want it to happen inside script step).
|
|
||||||
script:
|
|
||||||
- go get -t -v ./...
|
|
||||||
- diff -u <(echo -n) <(gofmt -d -s .)
|
|
||||||
- # vet is reporting "possible misuse of unsafe.Pointer", need to fix that.
|
|
||||||
- # go tool vet .
|
|
||||||
- go test -v -race ./...
|
|
|
@ -1,65 +0,0 @@
|
||||||
# gl [](https://travis-ci.org/go-gl/gl) [](https://godoc.org/github.com/go-gl/gl)
|
|
||||||
|
|
||||||
This repository holds Go bindings to various OpenGL versions. They are auto-generated using [Glow](https://github.com/go-gl/glow).
|
|
||||||
|
|
||||||
Features:
|
|
||||||
- Go functions that mirror the C specification using Go types.
|
|
||||||
- Support for multiple OpenGL APIs (GL/GLES/EGL/WGL/GLX/EGL), versions, and profiles.
|
|
||||||
- Support for extensions (including debug callbacks).
|
|
||||||
|
|
||||||
Requirements:
|
|
||||||
- A cgo compiler (typically gcc).
|
|
||||||
- On Ubuntu/Debian-based systems, the `libgl1-mesa-dev` package.
|
|
||||||
|
|
||||||
Usage
|
|
||||||
-----
|
|
||||||
|
|
||||||
Use `go get -u` to download and install the prebuilt packages. The prebuilt packages support OpenGL versions 2.1, 3.1, 3.2, 3.3, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6 across both the core and compatibility profiles and include all extensions. Pick whichever one(s) you need:
|
|
||||||
|
|
||||||
go get -u github.com/go-gl/gl/v{3.2,3.3,4.1,4.2,4.3,4.4,4.5,4.6}-{core,compatibility}/gl
|
|
||||||
go get -u github.com/go-gl/gl/v3.1/gles2
|
|
||||||
go get -u github.com/go-gl/gl/v2.1/gl
|
|
||||||
|
|
||||||
Once the bindings are installed you can use them with the appropriate import statements.
|
|
||||||
|
|
||||||
```Go
|
|
||||||
import "github.com/go-gl/gl/v3.3-core/gl"
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
window := ... // Open a window.
|
|
||||||
window.MakeContextCurrent()
|
|
||||||
|
|
||||||
// Important! Call gl.Init only under the presence of an active OpenGL context,
|
|
||||||
// i.e., after MakeContextCurrent.
|
|
||||||
if err := gl.Init(); err != nil {
|
|
||||||
log.Fatalln(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
The `gl` package contains the OpenGL functions and enumeration values for the imported version. It also contains helper functions for working with the API. Of note is `gl.Ptr` which takes a Go array or slice or pointer and returns a corresponding `uintptr` to use with functions expecting data pointers. Also of note is `gl.Str` which takes a null-terminated Go string and returns a corresponding `*int8` to use with functions expecting character pointers.
|
|
||||||
|
|
||||||
A note about threading and goroutines. The bindings do not expose a mechanism to make an OpenGL context current on a different thread so you must restrict your usage to the thread on which you called `gl.Init()`. To do so you should use [LockOSThread](https://code.google.com/p/go-wiki/wiki/LockOSThread).
|
|
||||||
|
|
||||||
Examples
|
|
||||||
--------
|
|
||||||
|
|
||||||
Examples illustrating how to use the bindings are available in the [example](https://github.com/go-gl/example) repo. There are examples for [OpenGL 4.1 core](https://github.com/go-gl/example/tree/master/gl41core-cube) and [OpenGL 2.1](https://github.com/go-gl/example/tree/master/gl21-cube).
|
|
||||||
|
|
||||||
Function Loading
|
|
||||||
----------------
|
|
||||||
|
|
||||||
The `procaddr` package contains platform-specific functions for [loading OpenGL functions](https://www.opengl.org/wiki/Load_OpenGL_Functions). Calling `gl.Init()` uses the `auto` subpackage to automatically select an appropriate implementation based on the build environment. If you want to select a specific implementation you can use the `noauto` build tag and the `gl.InitWithProcAddrFunc` initialization function.
|
|
||||||
|
|
||||||
Generating
|
|
||||||
----------
|
|
||||||
|
|
||||||
These gl bindings are generated using the [Glow](https://github.com/go-gl/glow) generator. Only developers of this repository need to do this step.
|
|
||||||
|
|
||||||
It is required to have `glow` source in the same Go workspace (since relative paths are used) and the `glow` binary should be in your `$PATH`. Doable with `go get -u github.com/go-gl/glow` if your `$GOPATH/bin` is in your `$PATH`.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
go generate -tags=gen github.com/go-gl/gl
|
|
||||||
```
|
|
||||||
|
|
||||||
More information about these bindings can be found in the [Glow repository](https://github.com/go-gl/glow).
|
|
|
@ -1,25 +0,0 @@
|
||||||
// +build gen
|
|
||||||
|
|
||||||
//go:generate glow generate -out=./v2.1/gl/ -api=gl -version=2.1 -xml=../glow/xml/
|
|
||||||
//go:generate glow generate -out=./all-core/gl/ -api=gl -version=all -profile=core -lenientInit -xml=../glow/xml/
|
|
||||||
//go:generate glow generate -out=./v3.2-core/gl/ -api=gl -version=3.2 -profile=core -xml=../glow/xml/
|
|
||||||
//go:generate glow generate -out=./v3.3-core/gl/ -api=gl -version=3.3 -profile=core -xml=../glow/xml/
|
|
||||||
//go:generate glow generate -out=./v4.1-core/gl/ -api=gl -version=4.1 -profile=core -xml=../glow/xml/
|
|
||||||
//go:generate glow generate -out=./v4.2-core/gl/ -api=gl -version=4.2 -profile=core -xml=../glow/xml/
|
|
||||||
//go:generate glow generate -out=./v4.3-core/gl/ -api=gl -version=4.3 -profile=core -xml=../glow/xml/
|
|
||||||
//go:generate glow generate -out=./v4.4-core/gl/ -api=gl -version=4.4 -profile=core -xml=../glow/xml/
|
|
||||||
//go:generate glow generate -out=./v4.5-core/gl/ -api=gl -version=4.5 -profile=core -xml=../glow/xml/
|
|
||||||
//go:generate glow generate -out=./v4.6-core/gl/ -api=gl -version=4.6 -profile=core -xml=../glow/xml/
|
|
||||||
//go:generate glow generate -out=./v3.2-compatibility/gl/ -api=gl -version=3.2 -profile=compatibility -xml=../glow/xml/
|
|
||||||
//go:generate glow generate -out=./v3.3-compatibility/gl/ -api=gl -version=3.3 -profile=compatibility -xml=../glow/xml/
|
|
||||||
//go:generate glow generate -out=./v4.1-compatibility/gl/ -api=gl -version=4.1 -profile=compatibility -xml=../glow/xml/
|
|
||||||
//go:generate glow generate -out=./v4.2-compatibility/gl/ -api=gl -version=4.2 -profile=compatibility -xml=../glow/xml/
|
|
||||||
//go:generate glow generate -out=./v4.3-compatibility/gl/ -api=gl -version=4.3 -profile=compatibility -xml=../glow/xml/
|
|
||||||
//go:generate glow generate -out=./v4.4-compatibility/gl/ -api=gl -version=4.4 -profile=compatibility -xml=../glow/xml/
|
|
||||||
//go:generate glow generate -out=./v4.5-compatibility/gl/ -api=gl -version=4.5 -profile=compatibility -xml=../glow/xml/
|
|
||||||
//go:generate glow generate -out=./v4.6-compatibility/gl/ -api=gl -version=4.6 -profile=compatibility -xml=../glow/xml/
|
|
||||||
//go:generate glow generate -out=./v3.1/gles2/ -api=gles2 -version=3.1 -xml=../glow/xml/
|
|
||||||
|
|
||||||
// This is an empty pseudo-package with the sole purpose of containing go generate directives
|
|
||||||
// that generate all gl binding packages inside this repository.
|
|
||||||
package gl
|
|
|
@ -1,109 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// #include <stdlib.h>
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
// Ptr takes a slice or pointer (to a singular scalar value or the first
|
|
||||||
// element of an array or slice) and returns its GL-compatible address.
|
|
||||||
//
|
|
||||||
// For example:
|
|
||||||
//
|
|
||||||
// var data []uint8
|
|
||||||
// ...
|
|
||||||
// gl.TexImage2D(gl.TEXTURE_2D, ..., gl.UNSIGNED_BYTE, gl.Ptr(&data[0]))
|
|
||||||
func Ptr(data interface{}) unsafe.Pointer {
|
|
||||||
if data == nil {
|
|
||||||
return unsafe.Pointer(nil)
|
|
||||||
}
|
|
||||||
var addr unsafe.Pointer
|
|
||||||
v := reflect.ValueOf(data)
|
|
||||||
switch v.Type().Kind() {
|
|
||||||
case reflect.Ptr:
|
|
||||||
e := v.Elem()
|
|
||||||
switch e.Kind() {
|
|
||||||
case
|
|
||||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
|
||||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
|
||||||
reflect.Float32, reflect.Float64:
|
|
||||||
addr = unsafe.Pointer(e.UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported pointer to type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", e.Kind()))
|
|
||||||
}
|
|
||||||
case reflect.Uintptr:
|
|
||||||
addr = unsafe.Pointer(v.Pointer())
|
|
||||||
case reflect.Slice:
|
|
||||||
addr = unsafe.Pointer(v.Index(0).UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", v.Type()))
|
|
||||||
}
|
|
||||||
return addr
|
|
||||||
}
|
|
||||||
|
|
||||||
// PtrOffset takes a pointer offset and returns a GL-compatible pointer.
|
|
||||||
// Useful for functions such as glVertexAttribPointer that take pointer
|
|
||||||
// parameters indicating an offset rather than an absolute memory address.
|
|
||||||
func PtrOffset(offset int) unsafe.Pointer {
|
|
||||||
return unsafe.Pointer(uintptr(offset))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Str takes a null-terminated Go string and returns its GL-compatible address.
|
|
||||||
// This function reaches into Go string storage in an unsafe way so the caller
|
|
||||||
// must ensure the string is not garbage collected.
|
|
||||||
func Str(str string) *uint8 {
|
|
||||||
if !strings.HasSuffix(str, "\x00") {
|
|
||||||
panic("str argument missing null terminator: " + str)
|
|
||||||
}
|
|
||||||
header := (*reflect.StringHeader)(unsafe.Pointer(&str))
|
|
||||||
return (*uint8)(unsafe.Pointer(header.Data))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GoStr takes a null-terminated string returned by OpenGL and constructs a
|
|
||||||
// corresponding Go string.
|
|
||||||
func GoStr(cstr *uint8) string {
|
|
||||||
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strs takes a list of Go strings (with or without null-termination) and
|
|
||||||
// returns their C counterpart.
|
|
||||||
//
|
|
||||||
// The returned free function must be called once you are done using the strings
|
|
||||||
// in order to free the memory.
|
|
||||||
//
|
|
||||||
// If no strings are provided as a parameter this function will panic.
|
|
||||||
func Strs(strs ...string) (cstrs **uint8, free func()) {
|
|
||||||
if len(strs) == 0 {
|
|
||||||
panic("Strs: expected at least 1 string")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate a contiguous array large enough to hold all the strings' contents.
|
|
||||||
n := 0
|
|
||||||
for i := range strs {
|
|
||||||
n += len(strs[i])
|
|
||||||
}
|
|
||||||
data := C.malloc(C.size_t(n))
|
|
||||||
|
|
||||||
// Copy all the strings into data.
|
|
||||||
dataSlice := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
|
|
||||||
Data: uintptr(data),
|
|
||||||
Len: n,
|
|
||||||
Cap: n,
|
|
||||||
}))
|
|
||||||
css := make([]*uint8, len(strs)) // Populated with pointers to each string.
|
|
||||||
offset := 0
|
|
||||||
for i := range strs {
|
|
||||||
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
|
|
||||||
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
|
|
||||||
offset += len(strs[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
return (**uint8)(&css[0]), func() { C.free(data) }
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
type DebugProc func(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message string,
|
|
||||||
userParam unsafe.Pointer)
|
|
||||||
|
|
||||||
var userDebugCallback DebugProc
|
|
||||||
|
|
||||||
//export glowDebugCallback_gl21
|
|
||||||
func glowDebugCallback_gl21(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message *uint8,
|
|
||||||
userParam unsafe.Pointer) {
|
|
||||||
if userDebugCallback != nil {
|
|
||||||
userDebugCallback(source, gltype, id, severity, length, GoStr(message), userParam)
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,71 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
// This file implements GlowGetProcAddress for every supported platform. The
|
|
||||||
// correct version is chosen automatically based on build tags:
|
|
||||||
//
|
|
||||||
// windows: WGL
|
|
||||||
// darwin: CGL
|
|
||||||
// linux freebsd: GLX
|
|
||||||
//
|
|
||||||
// Use of EGL instead of the platform's default (listed above) is made possible
|
|
||||||
// via the "egl" build tag.
|
|
||||||
//
|
|
||||||
// It is also possible to install your own function outside this package for
|
|
||||||
// retrieving OpenGL function pointers, to do this see InitWithProcAddrFunc.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
/*
|
|
||||||
#cgo windows CFLAGS: -DTAG_WINDOWS
|
|
||||||
#cgo windows LDFLAGS: -lopengl32
|
|
||||||
#cgo darwin CFLAGS: -DTAG_DARWIN
|
|
||||||
#cgo darwin LDFLAGS: -framework OpenGL
|
|
||||||
#cgo linux freebsd CFLAGS: -DTAG_POSIX
|
|
||||||
#cgo linux freebsd LDFLAGS: -lGL
|
|
||||||
#cgo egl CFLAGS: -DTAG_EGL
|
|
||||||
#cgo egl LDFLAGS: -lEGL
|
|
||||||
// Check the EGL tag first as it takes priority over the platform's default
|
|
||||||
// configuration of WGL/GLX/CGL.
|
|
||||||
#if defined(TAG_EGL)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <EGL/egl.h>
|
|
||||||
void* GlowGetProcAddress_gl21(const char* name) {
|
|
||||||
return eglGetProcAddress(name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_WINDOWS)
|
|
||||||
#define WIN32_LEAN_AND_MEAN 1
|
|
||||||
#include <windows.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
static HMODULE ogl32dll = NULL;
|
|
||||||
void* GlowGetProcAddress_gl21(const char* name) {
|
|
||||||
void* pf = wglGetProcAddress((LPCSTR) name);
|
|
||||||
if (pf) {
|
|
||||||
return pf;
|
|
||||||
}
|
|
||||||
if (ogl32dll == NULL) {
|
|
||||||
ogl32dll = LoadLibraryA("opengl32.dll");
|
|
||||||
}
|
|
||||||
return GetProcAddress(ogl32dll, (LPCSTR) name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_DARWIN)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <dlfcn.h>
|
|
||||||
void* GlowGetProcAddress_gl21(const char* name) {
|
|
||||||
return dlsym(RTLD_DEFAULT, name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_POSIX)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <GL/glx.h>
|
|
||||||
void* GlowGetProcAddress_gl21(const char* name) {
|
|
||||||
return glXGetProcAddress((const GLubyte *) name);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
func getProcAddress(namea string) unsafe.Pointer {
|
|
||||||
cname := C.CString(namea)
|
|
||||||
defer C.free(unsafe.Pointer(cname))
|
|
||||||
return C.GlowGetProcAddress_gl21(cname)
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gles2
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// #include <stdlib.h>
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
// Ptr takes a slice or pointer (to a singular scalar value or the first
|
|
||||||
// element of an array or slice) and returns its GL-compatible address.
|
|
||||||
//
|
|
||||||
// For example:
|
|
||||||
//
|
|
||||||
// var data []uint8
|
|
||||||
// ...
|
|
||||||
// gl.TexImage2D(gl.TEXTURE_2D, ..., gl.UNSIGNED_BYTE, gl.Ptr(&data[0]))
|
|
||||||
func Ptr(data interface{}) unsafe.Pointer {
|
|
||||||
if data == nil {
|
|
||||||
return unsafe.Pointer(nil)
|
|
||||||
}
|
|
||||||
var addr unsafe.Pointer
|
|
||||||
v := reflect.ValueOf(data)
|
|
||||||
switch v.Type().Kind() {
|
|
||||||
case reflect.Ptr:
|
|
||||||
e := v.Elem()
|
|
||||||
switch e.Kind() {
|
|
||||||
case
|
|
||||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
|
||||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
|
||||||
reflect.Float32, reflect.Float64:
|
|
||||||
addr = unsafe.Pointer(e.UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported pointer to type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", e.Kind()))
|
|
||||||
}
|
|
||||||
case reflect.Uintptr:
|
|
||||||
addr = unsafe.Pointer(v.Pointer())
|
|
||||||
case reflect.Slice:
|
|
||||||
addr = unsafe.Pointer(v.Index(0).UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", v.Type()))
|
|
||||||
}
|
|
||||||
return addr
|
|
||||||
}
|
|
||||||
|
|
||||||
// PtrOffset takes a pointer offset and returns a GL-compatible pointer.
|
|
||||||
// Useful for functions such as glVertexAttribPointer that take pointer
|
|
||||||
// parameters indicating an offset rather than an absolute memory address.
|
|
||||||
func PtrOffset(offset int) unsafe.Pointer {
|
|
||||||
return unsafe.Pointer(uintptr(offset))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Str takes a null-terminated Go string and returns its GL-compatible address.
|
|
||||||
// This function reaches into Go string storage in an unsafe way so the caller
|
|
||||||
// must ensure the string is not garbage collected.
|
|
||||||
func Str(str string) *uint8 {
|
|
||||||
if !strings.HasSuffix(str, "\x00") {
|
|
||||||
panic("str argument missing null terminator: " + str)
|
|
||||||
}
|
|
||||||
header := (*reflect.StringHeader)(unsafe.Pointer(&str))
|
|
||||||
return (*uint8)(unsafe.Pointer(header.Data))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GoStr takes a null-terminated string returned by OpenGL and constructs a
|
|
||||||
// corresponding Go string.
|
|
||||||
func GoStr(cstr *uint8) string {
|
|
||||||
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strs takes a list of Go strings (with or without null-termination) and
|
|
||||||
// returns their C counterpart.
|
|
||||||
//
|
|
||||||
// The returned free function must be called once you are done using the strings
|
|
||||||
// in order to free the memory.
|
|
||||||
//
|
|
||||||
// If no strings are provided as a parameter this function will panic.
|
|
||||||
func Strs(strs ...string) (cstrs **uint8, free func()) {
|
|
||||||
if len(strs) == 0 {
|
|
||||||
panic("Strs: expected at least 1 string")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate a contiguous array large enough to hold all the strings' contents.
|
|
||||||
n := 0
|
|
||||||
for i := range strs {
|
|
||||||
n += len(strs[i])
|
|
||||||
}
|
|
||||||
data := C.malloc(C.size_t(n))
|
|
||||||
|
|
||||||
// Copy all the strings into data.
|
|
||||||
dataSlice := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
|
|
||||||
Data: uintptr(data),
|
|
||||||
Len: n,
|
|
||||||
Cap: n,
|
|
||||||
}))
|
|
||||||
css := make([]*uint8, len(strs)) // Populated with pointers to each string.
|
|
||||||
offset := 0
|
|
||||||
for i := range strs {
|
|
||||||
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
|
|
||||||
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
|
|
||||||
offset += len(strs[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
return (**uint8)(&css[0]), func() { C.free(data) }
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gles2
|
|
||||||
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
type DebugProc func(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message string,
|
|
||||||
userParam unsafe.Pointer)
|
|
||||||
|
|
||||||
var userDebugCallback DebugProc
|
|
||||||
|
|
||||||
//export glowDebugCallback_gles231
|
|
||||||
func glowDebugCallback_gles231(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message *uint8,
|
|
||||||
userParam unsafe.Pointer) {
|
|
||||||
if userDebugCallback != nil {
|
|
||||||
userDebugCallback(source, gltype, id, severity, length, GoStr(message), userParam)
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,71 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
// This file implements GlowGetProcAddress for every supported platform. The
|
|
||||||
// correct version is chosen automatically based on build tags:
|
|
||||||
//
|
|
||||||
// windows: WGL
|
|
||||||
// darwin: CGL
|
|
||||||
// linux freebsd: GLX
|
|
||||||
//
|
|
||||||
// Use of EGL instead of the platform's default (listed above) is made possible
|
|
||||||
// via the "egl" build tag.
|
|
||||||
//
|
|
||||||
// It is also possible to install your own function outside this package for
|
|
||||||
// retrieving OpenGL function pointers, to do this see InitWithProcAddrFunc.
|
|
||||||
|
|
||||||
package gles2
|
|
||||||
|
|
||||||
/*
|
|
||||||
#cgo windows CFLAGS: -DTAG_WINDOWS
|
|
||||||
#cgo windows LDFLAGS: -lopengl32
|
|
||||||
#cgo darwin CFLAGS: -DTAG_DARWIN
|
|
||||||
#cgo darwin LDFLAGS: -framework OpenGL
|
|
||||||
#cgo linux freebsd CFLAGS: -DTAG_POSIX
|
|
||||||
#cgo linux freebsd LDFLAGS: -lGL
|
|
||||||
#cgo egl CFLAGS: -DTAG_EGL
|
|
||||||
#cgo egl LDFLAGS: -lEGL
|
|
||||||
// Check the EGL tag first as it takes priority over the platform's default
|
|
||||||
// configuration of WGL/GLX/CGL.
|
|
||||||
#if defined(TAG_EGL)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <EGL/egl.h>
|
|
||||||
void* GlowGetProcAddress_gles231(const char* name) {
|
|
||||||
return eglGetProcAddress(name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_WINDOWS)
|
|
||||||
#define WIN32_LEAN_AND_MEAN 1
|
|
||||||
#include <windows.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
static HMODULE ogl32dll = NULL;
|
|
||||||
void* GlowGetProcAddress_gles231(const char* name) {
|
|
||||||
void* pf = wglGetProcAddress((LPCSTR) name);
|
|
||||||
if (pf) {
|
|
||||||
return pf;
|
|
||||||
}
|
|
||||||
if (ogl32dll == NULL) {
|
|
||||||
ogl32dll = LoadLibraryA("opengl32.dll");
|
|
||||||
}
|
|
||||||
return GetProcAddress(ogl32dll, (LPCSTR) name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_DARWIN)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <dlfcn.h>
|
|
||||||
void* GlowGetProcAddress_gles231(const char* name) {
|
|
||||||
return dlsym(RTLD_DEFAULT, name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_POSIX)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <GL/glx.h>
|
|
||||||
void* GlowGetProcAddress_gles231(const char* name) {
|
|
||||||
return glXGetProcAddress((const GLubyte *) name);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
func getProcAddress(namea string) unsafe.Pointer {
|
|
||||||
cname := C.CString(namea)
|
|
||||||
defer C.free(unsafe.Pointer(cname))
|
|
||||||
return C.GlowGetProcAddress_gles231(cname)
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// #include <stdlib.h>
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
// Ptr takes a slice or pointer (to a singular scalar value or the first
|
|
||||||
// element of an array or slice) and returns its GL-compatible address.
|
|
||||||
//
|
|
||||||
// For example:
|
|
||||||
//
|
|
||||||
// var data []uint8
|
|
||||||
// ...
|
|
||||||
// gl.TexImage2D(gl.TEXTURE_2D, ..., gl.UNSIGNED_BYTE, gl.Ptr(&data[0]))
|
|
||||||
func Ptr(data interface{}) unsafe.Pointer {
|
|
||||||
if data == nil {
|
|
||||||
return unsafe.Pointer(nil)
|
|
||||||
}
|
|
||||||
var addr unsafe.Pointer
|
|
||||||
v := reflect.ValueOf(data)
|
|
||||||
switch v.Type().Kind() {
|
|
||||||
case reflect.Ptr:
|
|
||||||
e := v.Elem()
|
|
||||||
switch e.Kind() {
|
|
||||||
case
|
|
||||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
|
||||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
|
||||||
reflect.Float32, reflect.Float64:
|
|
||||||
addr = unsafe.Pointer(e.UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported pointer to type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", e.Kind()))
|
|
||||||
}
|
|
||||||
case reflect.Uintptr:
|
|
||||||
addr = unsafe.Pointer(v.Pointer())
|
|
||||||
case reflect.Slice:
|
|
||||||
addr = unsafe.Pointer(v.Index(0).UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", v.Type()))
|
|
||||||
}
|
|
||||||
return addr
|
|
||||||
}
|
|
||||||
|
|
||||||
// PtrOffset takes a pointer offset and returns a GL-compatible pointer.
|
|
||||||
// Useful for functions such as glVertexAttribPointer that take pointer
|
|
||||||
// parameters indicating an offset rather than an absolute memory address.
|
|
||||||
func PtrOffset(offset int) unsafe.Pointer {
|
|
||||||
return unsafe.Pointer(uintptr(offset))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Str takes a null-terminated Go string and returns its GL-compatible address.
|
|
||||||
// This function reaches into Go string storage in an unsafe way so the caller
|
|
||||||
// must ensure the string is not garbage collected.
|
|
||||||
func Str(str string) *uint8 {
|
|
||||||
if !strings.HasSuffix(str, "\x00") {
|
|
||||||
panic("str argument missing null terminator: " + str)
|
|
||||||
}
|
|
||||||
header := (*reflect.StringHeader)(unsafe.Pointer(&str))
|
|
||||||
return (*uint8)(unsafe.Pointer(header.Data))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GoStr takes a null-terminated string returned by OpenGL and constructs a
|
|
||||||
// corresponding Go string.
|
|
||||||
func GoStr(cstr *uint8) string {
|
|
||||||
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strs takes a list of Go strings (with or without null-termination) and
|
|
||||||
// returns their C counterpart.
|
|
||||||
//
|
|
||||||
// The returned free function must be called once you are done using the strings
|
|
||||||
// in order to free the memory.
|
|
||||||
//
|
|
||||||
// If no strings are provided as a parameter this function will panic.
|
|
||||||
func Strs(strs ...string) (cstrs **uint8, free func()) {
|
|
||||||
if len(strs) == 0 {
|
|
||||||
panic("Strs: expected at least 1 string")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate a contiguous array large enough to hold all the strings' contents.
|
|
||||||
n := 0
|
|
||||||
for i := range strs {
|
|
||||||
n += len(strs[i])
|
|
||||||
}
|
|
||||||
data := C.malloc(C.size_t(n))
|
|
||||||
|
|
||||||
// Copy all the strings into data.
|
|
||||||
dataSlice := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
|
|
||||||
Data: uintptr(data),
|
|
||||||
Len: n,
|
|
||||||
Cap: n,
|
|
||||||
}))
|
|
||||||
css := make([]*uint8, len(strs)) // Populated with pointers to each string.
|
|
||||||
offset := 0
|
|
||||||
for i := range strs {
|
|
||||||
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
|
|
||||||
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
|
|
||||||
offset += len(strs[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
return (**uint8)(&css[0]), func() { C.free(data) }
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
type DebugProc func(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message string,
|
|
||||||
userParam unsafe.Pointer)
|
|
||||||
|
|
||||||
var userDebugCallback DebugProc
|
|
||||||
|
|
||||||
//export glowDebugCallback_glcompatibility32
|
|
||||||
func glowDebugCallback_glcompatibility32(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message *uint8,
|
|
||||||
userParam unsafe.Pointer) {
|
|
||||||
if userDebugCallback != nil {
|
|
||||||
userDebugCallback(source, gltype, id, severity, length, GoStr(message), userParam)
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,71 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
// This file implements GlowGetProcAddress for every supported platform. The
|
|
||||||
// correct version is chosen automatically based on build tags:
|
|
||||||
//
|
|
||||||
// windows: WGL
|
|
||||||
// darwin: CGL
|
|
||||||
// linux freebsd: GLX
|
|
||||||
//
|
|
||||||
// Use of EGL instead of the platform's default (listed above) is made possible
|
|
||||||
// via the "egl" build tag.
|
|
||||||
//
|
|
||||||
// It is also possible to install your own function outside this package for
|
|
||||||
// retrieving OpenGL function pointers, to do this see InitWithProcAddrFunc.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
/*
|
|
||||||
#cgo windows CFLAGS: -DTAG_WINDOWS
|
|
||||||
#cgo windows LDFLAGS: -lopengl32
|
|
||||||
#cgo darwin CFLAGS: -DTAG_DARWIN
|
|
||||||
#cgo darwin LDFLAGS: -framework OpenGL
|
|
||||||
#cgo linux freebsd CFLAGS: -DTAG_POSIX
|
|
||||||
#cgo linux freebsd LDFLAGS: -lGL
|
|
||||||
#cgo egl CFLAGS: -DTAG_EGL
|
|
||||||
#cgo egl LDFLAGS: -lEGL
|
|
||||||
// Check the EGL tag first as it takes priority over the platform's default
|
|
||||||
// configuration of WGL/GLX/CGL.
|
|
||||||
#if defined(TAG_EGL)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <EGL/egl.h>
|
|
||||||
void* GlowGetProcAddress_glcompatibility32(const char* name) {
|
|
||||||
return eglGetProcAddress(name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_WINDOWS)
|
|
||||||
#define WIN32_LEAN_AND_MEAN 1
|
|
||||||
#include <windows.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
static HMODULE ogl32dll = NULL;
|
|
||||||
void* GlowGetProcAddress_glcompatibility32(const char* name) {
|
|
||||||
void* pf = wglGetProcAddress((LPCSTR) name);
|
|
||||||
if (pf) {
|
|
||||||
return pf;
|
|
||||||
}
|
|
||||||
if (ogl32dll == NULL) {
|
|
||||||
ogl32dll = LoadLibraryA("opengl32.dll");
|
|
||||||
}
|
|
||||||
return GetProcAddress(ogl32dll, (LPCSTR) name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_DARWIN)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <dlfcn.h>
|
|
||||||
void* GlowGetProcAddress_glcompatibility32(const char* name) {
|
|
||||||
return dlsym(RTLD_DEFAULT, name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_POSIX)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <GL/glx.h>
|
|
||||||
void* GlowGetProcAddress_glcompatibility32(const char* name) {
|
|
||||||
return glXGetProcAddress((const GLubyte *) name);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
func getProcAddress(namea string) unsafe.Pointer {
|
|
||||||
cname := C.CString(namea)
|
|
||||||
defer C.free(unsafe.Pointer(cname))
|
|
||||||
return C.GlowGetProcAddress_glcompatibility32(cname)
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// #include <stdlib.h>
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
// Ptr takes a slice or pointer (to a singular scalar value or the first
|
|
||||||
// element of an array or slice) and returns its GL-compatible address.
|
|
||||||
//
|
|
||||||
// For example:
|
|
||||||
//
|
|
||||||
// var data []uint8
|
|
||||||
// ...
|
|
||||||
// gl.TexImage2D(gl.TEXTURE_2D, ..., gl.UNSIGNED_BYTE, gl.Ptr(&data[0]))
|
|
||||||
func Ptr(data interface{}) unsafe.Pointer {
|
|
||||||
if data == nil {
|
|
||||||
return unsafe.Pointer(nil)
|
|
||||||
}
|
|
||||||
var addr unsafe.Pointer
|
|
||||||
v := reflect.ValueOf(data)
|
|
||||||
switch v.Type().Kind() {
|
|
||||||
case reflect.Ptr:
|
|
||||||
e := v.Elem()
|
|
||||||
switch e.Kind() {
|
|
||||||
case
|
|
||||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
|
||||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
|
||||||
reflect.Float32, reflect.Float64:
|
|
||||||
addr = unsafe.Pointer(e.UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported pointer to type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", e.Kind()))
|
|
||||||
}
|
|
||||||
case reflect.Uintptr:
|
|
||||||
addr = unsafe.Pointer(v.Pointer())
|
|
||||||
case reflect.Slice:
|
|
||||||
addr = unsafe.Pointer(v.Index(0).UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", v.Type()))
|
|
||||||
}
|
|
||||||
return addr
|
|
||||||
}
|
|
||||||
|
|
||||||
// PtrOffset takes a pointer offset and returns a GL-compatible pointer.
|
|
||||||
// Useful for functions such as glVertexAttribPointer that take pointer
|
|
||||||
// parameters indicating an offset rather than an absolute memory address.
|
|
||||||
func PtrOffset(offset int) unsafe.Pointer {
|
|
||||||
return unsafe.Pointer(uintptr(offset))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Str takes a null-terminated Go string and returns its GL-compatible address.
|
|
||||||
// This function reaches into Go string storage in an unsafe way so the caller
|
|
||||||
// must ensure the string is not garbage collected.
|
|
||||||
func Str(str string) *uint8 {
|
|
||||||
if !strings.HasSuffix(str, "\x00") {
|
|
||||||
panic("str argument missing null terminator: " + str)
|
|
||||||
}
|
|
||||||
header := (*reflect.StringHeader)(unsafe.Pointer(&str))
|
|
||||||
return (*uint8)(unsafe.Pointer(header.Data))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GoStr takes a null-terminated string returned by OpenGL and constructs a
|
|
||||||
// corresponding Go string.
|
|
||||||
func GoStr(cstr *uint8) string {
|
|
||||||
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strs takes a list of Go strings (with or without null-termination) and
|
|
||||||
// returns their C counterpart.
|
|
||||||
//
|
|
||||||
// The returned free function must be called once you are done using the strings
|
|
||||||
// in order to free the memory.
|
|
||||||
//
|
|
||||||
// If no strings are provided as a parameter this function will panic.
|
|
||||||
func Strs(strs ...string) (cstrs **uint8, free func()) {
|
|
||||||
if len(strs) == 0 {
|
|
||||||
panic("Strs: expected at least 1 string")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate a contiguous array large enough to hold all the strings' contents.
|
|
||||||
n := 0
|
|
||||||
for i := range strs {
|
|
||||||
n += len(strs[i])
|
|
||||||
}
|
|
||||||
data := C.malloc(C.size_t(n))
|
|
||||||
|
|
||||||
// Copy all the strings into data.
|
|
||||||
dataSlice := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
|
|
||||||
Data: uintptr(data),
|
|
||||||
Len: n,
|
|
||||||
Cap: n,
|
|
||||||
}))
|
|
||||||
css := make([]*uint8, len(strs)) // Populated with pointers to each string.
|
|
||||||
offset := 0
|
|
||||||
for i := range strs {
|
|
||||||
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
|
|
||||||
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
|
|
||||||
offset += len(strs[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
return (**uint8)(&css[0]), func() { C.free(data) }
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
type DebugProc func(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message string,
|
|
||||||
userParam unsafe.Pointer)
|
|
||||||
|
|
||||||
var userDebugCallback DebugProc
|
|
||||||
|
|
||||||
//export glowDebugCallback_glcore32
|
|
||||||
func glowDebugCallback_glcore32(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message *uint8,
|
|
||||||
userParam unsafe.Pointer) {
|
|
||||||
if userDebugCallback != nil {
|
|
||||||
userDebugCallback(source, gltype, id, severity, length, GoStr(message), userParam)
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,71 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
// This file implements GlowGetProcAddress for every supported platform. The
|
|
||||||
// correct version is chosen automatically based on build tags:
|
|
||||||
//
|
|
||||||
// windows: WGL
|
|
||||||
// darwin: CGL
|
|
||||||
// linux freebsd: GLX
|
|
||||||
//
|
|
||||||
// Use of EGL instead of the platform's default (listed above) is made possible
|
|
||||||
// via the "egl" build tag.
|
|
||||||
//
|
|
||||||
// It is also possible to install your own function outside this package for
|
|
||||||
// retrieving OpenGL function pointers, to do this see InitWithProcAddrFunc.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
/*
|
|
||||||
#cgo windows CFLAGS: -DTAG_WINDOWS
|
|
||||||
#cgo windows LDFLAGS: -lopengl32
|
|
||||||
#cgo darwin CFLAGS: -DTAG_DARWIN
|
|
||||||
#cgo darwin LDFLAGS: -framework OpenGL
|
|
||||||
#cgo linux freebsd CFLAGS: -DTAG_POSIX
|
|
||||||
#cgo linux freebsd LDFLAGS: -lGL
|
|
||||||
#cgo egl CFLAGS: -DTAG_EGL
|
|
||||||
#cgo egl LDFLAGS: -lEGL
|
|
||||||
// Check the EGL tag first as it takes priority over the platform's default
|
|
||||||
// configuration of WGL/GLX/CGL.
|
|
||||||
#if defined(TAG_EGL)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <EGL/egl.h>
|
|
||||||
void* GlowGetProcAddress_glcore32(const char* name) {
|
|
||||||
return eglGetProcAddress(name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_WINDOWS)
|
|
||||||
#define WIN32_LEAN_AND_MEAN 1
|
|
||||||
#include <windows.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
static HMODULE ogl32dll = NULL;
|
|
||||||
void* GlowGetProcAddress_glcore32(const char* name) {
|
|
||||||
void* pf = wglGetProcAddress((LPCSTR) name);
|
|
||||||
if (pf) {
|
|
||||||
return pf;
|
|
||||||
}
|
|
||||||
if (ogl32dll == NULL) {
|
|
||||||
ogl32dll = LoadLibraryA("opengl32.dll");
|
|
||||||
}
|
|
||||||
return GetProcAddress(ogl32dll, (LPCSTR) name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_DARWIN)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <dlfcn.h>
|
|
||||||
void* GlowGetProcAddress_glcore32(const char* name) {
|
|
||||||
return dlsym(RTLD_DEFAULT, name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_POSIX)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <GL/glx.h>
|
|
||||||
void* GlowGetProcAddress_glcore32(const char* name) {
|
|
||||||
return glXGetProcAddress((const GLubyte *) name);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
func getProcAddress(namea string) unsafe.Pointer {
|
|
||||||
cname := C.CString(namea)
|
|
||||||
defer C.free(unsafe.Pointer(cname))
|
|
||||||
return C.GlowGetProcAddress_glcore32(cname)
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// #include <stdlib.h>
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
// Ptr takes a slice or pointer (to a singular scalar value or the first
|
|
||||||
// element of an array or slice) and returns its GL-compatible address.
|
|
||||||
//
|
|
||||||
// For example:
|
|
||||||
//
|
|
||||||
// var data []uint8
|
|
||||||
// ...
|
|
||||||
// gl.TexImage2D(gl.TEXTURE_2D, ..., gl.UNSIGNED_BYTE, gl.Ptr(&data[0]))
|
|
||||||
func Ptr(data interface{}) unsafe.Pointer {
|
|
||||||
if data == nil {
|
|
||||||
return unsafe.Pointer(nil)
|
|
||||||
}
|
|
||||||
var addr unsafe.Pointer
|
|
||||||
v := reflect.ValueOf(data)
|
|
||||||
switch v.Type().Kind() {
|
|
||||||
case reflect.Ptr:
|
|
||||||
e := v.Elem()
|
|
||||||
switch e.Kind() {
|
|
||||||
case
|
|
||||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
|
||||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
|
||||||
reflect.Float32, reflect.Float64:
|
|
||||||
addr = unsafe.Pointer(e.UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported pointer to type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", e.Kind()))
|
|
||||||
}
|
|
||||||
case reflect.Uintptr:
|
|
||||||
addr = unsafe.Pointer(v.Pointer())
|
|
||||||
case reflect.Slice:
|
|
||||||
addr = unsafe.Pointer(v.Index(0).UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", v.Type()))
|
|
||||||
}
|
|
||||||
return addr
|
|
||||||
}
|
|
||||||
|
|
||||||
// PtrOffset takes a pointer offset and returns a GL-compatible pointer.
|
|
||||||
// Useful for functions such as glVertexAttribPointer that take pointer
|
|
||||||
// parameters indicating an offset rather than an absolute memory address.
|
|
||||||
func PtrOffset(offset int) unsafe.Pointer {
|
|
||||||
return unsafe.Pointer(uintptr(offset))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Str takes a null-terminated Go string and returns its GL-compatible address.
|
|
||||||
// This function reaches into Go string storage in an unsafe way so the caller
|
|
||||||
// must ensure the string is not garbage collected.
|
|
||||||
func Str(str string) *uint8 {
|
|
||||||
if !strings.HasSuffix(str, "\x00") {
|
|
||||||
panic("str argument missing null terminator: " + str)
|
|
||||||
}
|
|
||||||
header := (*reflect.StringHeader)(unsafe.Pointer(&str))
|
|
||||||
return (*uint8)(unsafe.Pointer(header.Data))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GoStr takes a null-terminated string returned by OpenGL and constructs a
|
|
||||||
// corresponding Go string.
|
|
||||||
func GoStr(cstr *uint8) string {
|
|
||||||
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strs takes a list of Go strings (with or without null-termination) and
|
|
||||||
// returns their C counterpart.
|
|
||||||
//
|
|
||||||
// The returned free function must be called once you are done using the strings
|
|
||||||
// in order to free the memory.
|
|
||||||
//
|
|
||||||
// If no strings are provided as a parameter this function will panic.
|
|
||||||
func Strs(strs ...string) (cstrs **uint8, free func()) {
|
|
||||||
if len(strs) == 0 {
|
|
||||||
panic("Strs: expected at least 1 string")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate a contiguous array large enough to hold all the strings' contents.
|
|
||||||
n := 0
|
|
||||||
for i := range strs {
|
|
||||||
n += len(strs[i])
|
|
||||||
}
|
|
||||||
data := C.malloc(C.size_t(n))
|
|
||||||
|
|
||||||
// Copy all the strings into data.
|
|
||||||
dataSlice := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
|
|
||||||
Data: uintptr(data),
|
|
||||||
Len: n,
|
|
||||||
Cap: n,
|
|
||||||
}))
|
|
||||||
css := make([]*uint8, len(strs)) // Populated with pointers to each string.
|
|
||||||
offset := 0
|
|
||||||
for i := range strs {
|
|
||||||
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
|
|
||||||
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
|
|
||||||
offset += len(strs[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
return (**uint8)(&css[0]), func() { C.free(data) }
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
type DebugProc func(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message string,
|
|
||||||
userParam unsafe.Pointer)
|
|
||||||
|
|
||||||
var userDebugCallback DebugProc
|
|
||||||
|
|
||||||
//export glowDebugCallback_glcompatibility33
|
|
||||||
func glowDebugCallback_glcompatibility33(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message *uint8,
|
|
||||||
userParam unsafe.Pointer) {
|
|
||||||
if userDebugCallback != nil {
|
|
||||||
userDebugCallback(source, gltype, id, severity, length, GoStr(message), userParam)
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,71 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
// This file implements GlowGetProcAddress for every supported platform. The
|
|
||||||
// correct version is chosen automatically based on build tags:
|
|
||||||
//
|
|
||||||
// windows: WGL
|
|
||||||
// darwin: CGL
|
|
||||||
// linux freebsd: GLX
|
|
||||||
//
|
|
||||||
// Use of EGL instead of the platform's default (listed above) is made possible
|
|
||||||
// via the "egl" build tag.
|
|
||||||
//
|
|
||||||
// It is also possible to install your own function outside this package for
|
|
||||||
// retrieving OpenGL function pointers, to do this see InitWithProcAddrFunc.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
/*
|
|
||||||
#cgo windows CFLAGS: -DTAG_WINDOWS
|
|
||||||
#cgo windows LDFLAGS: -lopengl32
|
|
||||||
#cgo darwin CFLAGS: -DTAG_DARWIN
|
|
||||||
#cgo darwin LDFLAGS: -framework OpenGL
|
|
||||||
#cgo linux freebsd CFLAGS: -DTAG_POSIX
|
|
||||||
#cgo linux freebsd LDFLAGS: -lGL
|
|
||||||
#cgo egl CFLAGS: -DTAG_EGL
|
|
||||||
#cgo egl LDFLAGS: -lEGL
|
|
||||||
// Check the EGL tag first as it takes priority over the platform's default
|
|
||||||
// configuration of WGL/GLX/CGL.
|
|
||||||
#if defined(TAG_EGL)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <EGL/egl.h>
|
|
||||||
void* GlowGetProcAddress_glcompatibility33(const char* name) {
|
|
||||||
return eglGetProcAddress(name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_WINDOWS)
|
|
||||||
#define WIN32_LEAN_AND_MEAN 1
|
|
||||||
#include <windows.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
static HMODULE ogl32dll = NULL;
|
|
||||||
void* GlowGetProcAddress_glcompatibility33(const char* name) {
|
|
||||||
void* pf = wglGetProcAddress((LPCSTR) name);
|
|
||||||
if (pf) {
|
|
||||||
return pf;
|
|
||||||
}
|
|
||||||
if (ogl32dll == NULL) {
|
|
||||||
ogl32dll = LoadLibraryA("opengl32.dll");
|
|
||||||
}
|
|
||||||
return GetProcAddress(ogl32dll, (LPCSTR) name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_DARWIN)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <dlfcn.h>
|
|
||||||
void* GlowGetProcAddress_glcompatibility33(const char* name) {
|
|
||||||
return dlsym(RTLD_DEFAULT, name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_POSIX)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <GL/glx.h>
|
|
||||||
void* GlowGetProcAddress_glcompatibility33(const char* name) {
|
|
||||||
return glXGetProcAddress((const GLubyte *) name);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
func getProcAddress(namea string) unsafe.Pointer {
|
|
||||||
cname := C.CString(namea)
|
|
||||||
defer C.free(unsafe.Pointer(cname))
|
|
||||||
return C.GlowGetProcAddress_glcompatibility33(cname)
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// #include <stdlib.h>
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
// Ptr takes a slice or pointer (to a singular scalar value or the first
|
|
||||||
// element of an array or slice) and returns its GL-compatible address.
|
|
||||||
//
|
|
||||||
// For example:
|
|
||||||
//
|
|
||||||
// var data []uint8
|
|
||||||
// ...
|
|
||||||
// gl.TexImage2D(gl.TEXTURE_2D, ..., gl.UNSIGNED_BYTE, gl.Ptr(&data[0]))
|
|
||||||
func Ptr(data interface{}) unsafe.Pointer {
|
|
||||||
if data == nil {
|
|
||||||
return unsafe.Pointer(nil)
|
|
||||||
}
|
|
||||||
var addr unsafe.Pointer
|
|
||||||
v := reflect.ValueOf(data)
|
|
||||||
switch v.Type().Kind() {
|
|
||||||
case reflect.Ptr:
|
|
||||||
e := v.Elem()
|
|
||||||
switch e.Kind() {
|
|
||||||
case
|
|
||||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
|
||||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
|
||||||
reflect.Float32, reflect.Float64:
|
|
||||||
addr = unsafe.Pointer(e.UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported pointer to type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", e.Kind()))
|
|
||||||
}
|
|
||||||
case reflect.Uintptr:
|
|
||||||
addr = unsafe.Pointer(v.Pointer())
|
|
||||||
case reflect.Slice:
|
|
||||||
addr = unsafe.Pointer(v.Index(0).UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", v.Type()))
|
|
||||||
}
|
|
||||||
return addr
|
|
||||||
}
|
|
||||||
|
|
||||||
// PtrOffset takes a pointer offset and returns a GL-compatible pointer.
|
|
||||||
// Useful for functions such as glVertexAttribPointer that take pointer
|
|
||||||
// parameters indicating an offset rather than an absolute memory address.
|
|
||||||
func PtrOffset(offset int) unsafe.Pointer {
|
|
||||||
return unsafe.Pointer(uintptr(offset))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Str takes a null-terminated Go string and returns its GL-compatible address.
|
|
||||||
// This function reaches into Go string storage in an unsafe way so the caller
|
|
||||||
// must ensure the string is not garbage collected.
|
|
||||||
func Str(str string) *uint8 {
|
|
||||||
if !strings.HasSuffix(str, "\x00") {
|
|
||||||
panic("str argument missing null terminator: " + str)
|
|
||||||
}
|
|
||||||
header := (*reflect.StringHeader)(unsafe.Pointer(&str))
|
|
||||||
return (*uint8)(unsafe.Pointer(header.Data))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GoStr takes a null-terminated string returned by OpenGL and constructs a
|
|
||||||
// corresponding Go string.
|
|
||||||
func GoStr(cstr *uint8) string {
|
|
||||||
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strs takes a list of Go strings (with or without null-termination) and
|
|
||||||
// returns their C counterpart.
|
|
||||||
//
|
|
||||||
// The returned free function must be called once you are done using the strings
|
|
||||||
// in order to free the memory.
|
|
||||||
//
|
|
||||||
// If no strings are provided as a parameter this function will panic.
|
|
||||||
func Strs(strs ...string) (cstrs **uint8, free func()) {
|
|
||||||
if len(strs) == 0 {
|
|
||||||
panic("Strs: expected at least 1 string")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate a contiguous array large enough to hold all the strings' contents.
|
|
||||||
n := 0
|
|
||||||
for i := range strs {
|
|
||||||
n += len(strs[i])
|
|
||||||
}
|
|
||||||
data := C.malloc(C.size_t(n))
|
|
||||||
|
|
||||||
// Copy all the strings into data.
|
|
||||||
dataSlice := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
|
|
||||||
Data: uintptr(data),
|
|
||||||
Len: n,
|
|
||||||
Cap: n,
|
|
||||||
}))
|
|
||||||
css := make([]*uint8, len(strs)) // Populated with pointers to each string.
|
|
||||||
offset := 0
|
|
||||||
for i := range strs {
|
|
||||||
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
|
|
||||||
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
|
|
||||||
offset += len(strs[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
return (**uint8)(&css[0]), func() { C.free(data) }
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
type DebugProc func(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message string,
|
|
||||||
userParam unsafe.Pointer)
|
|
||||||
|
|
||||||
var userDebugCallback DebugProc
|
|
||||||
|
|
||||||
//export glowDebugCallback_glcore33
|
|
||||||
func glowDebugCallback_glcore33(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message *uint8,
|
|
||||||
userParam unsafe.Pointer) {
|
|
||||||
if userDebugCallback != nil {
|
|
||||||
userDebugCallback(source, gltype, id, severity, length, GoStr(message), userParam)
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,71 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
// This file implements GlowGetProcAddress for every supported platform. The
|
|
||||||
// correct version is chosen automatically based on build tags:
|
|
||||||
//
|
|
||||||
// windows: WGL
|
|
||||||
// darwin: CGL
|
|
||||||
// linux freebsd: GLX
|
|
||||||
//
|
|
||||||
// Use of EGL instead of the platform's default (listed above) is made possible
|
|
||||||
// via the "egl" build tag.
|
|
||||||
//
|
|
||||||
// It is also possible to install your own function outside this package for
|
|
||||||
// retrieving OpenGL function pointers, to do this see InitWithProcAddrFunc.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
/*
|
|
||||||
#cgo windows CFLAGS: -DTAG_WINDOWS
|
|
||||||
#cgo windows LDFLAGS: -lopengl32
|
|
||||||
#cgo darwin CFLAGS: -DTAG_DARWIN
|
|
||||||
#cgo darwin LDFLAGS: -framework OpenGL
|
|
||||||
#cgo linux freebsd CFLAGS: -DTAG_POSIX
|
|
||||||
#cgo linux freebsd LDFLAGS: -lGL
|
|
||||||
#cgo egl CFLAGS: -DTAG_EGL
|
|
||||||
#cgo egl LDFLAGS: -lEGL
|
|
||||||
// Check the EGL tag first as it takes priority over the platform's default
|
|
||||||
// configuration of WGL/GLX/CGL.
|
|
||||||
#if defined(TAG_EGL)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <EGL/egl.h>
|
|
||||||
void* GlowGetProcAddress_glcore33(const char* name) {
|
|
||||||
return eglGetProcAddress(name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_WINDOWS)
|
|
||||||
#define WIN32_LEAN_AND_MEAN 1
|
|
||||||
#include <windows.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
static HMODULE ogl32dll = NULL;
|
|
||||||
void* GlowGetProcAddress_glcore33(const char* name) {
|
|
||||||
void* pf = wglGetProcAddress((LPCSTR) name);
|
|
||||||
if (pf) {
|
|
||||||
return pf;
|
|
||||||
}
|
|
||||||
if (ogl32dll == NULL) {
|
|
||||||
ogl32dll = LoadLibraryA("opengl32.dll");
|
|
||||||
}
|
|
||||||
return GetProcAddress(ogl32dll, (LPCSTR) name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_DARWIN)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <dlfcn.h>
|
|
||||||
void* GlowGetProcAddress_glcore33(const char* name) {
|
|
||||||
return dlsym(RTLD_DEFAULT, name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_POSIX)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <GL/glx.h>
|
|
||||||
void* GlowGetProcAddress_glcore33(const char* name) {
|
|
||||||
return glXGetProcAddress((const GLubyte *) name);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
func getProcAddress(namea string) unsafe.Pointer {
|
|
||||||
cname := C.CString(namea)
|
|
||||||
defer C.free(unsafe.Pointer(cname))
|
|
||||||
return C.GlowGetProcAddress_glcore33(cname)
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// #include <stdlib.h>
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
// Ptr takes a slice or pointer (to a singular scalar value or the first
|
|
||||||
// element of an array or slice) and returns its GL-compatible address.
|
|
||||||
//
|
|
||||||
// For example:
|
|
||||||
//
|
|
||||||
// var data []uint8
|
|
||||||
// ...
|
|
||||||
// gl.TexImage2D(gl.TEXTURE_2D, ..., gl.UNSIGNED_BYTE, gl.Ptr(&data[0]))
|
|
||||||
func Ptr(data interface{}) unsafe.Pointer {
|
|
||||||
if data == nil {
|
|
||||||
return unsafe.Pointer(nil)
|
|
||||||
}
|
|
||||||
var addr unsafe.Pointer
|
|
||||||
v := reflect.ValueOf(data)
|
|
||||||
switch v.Type().Kind() {
|
|
||||||
case reflect.Ptr:
|
|
||||||
e := v.Elem()
|
|
||||||
switch e.Kind() {
|
|
||||||
case
|
|
||||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
|
||||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
|
||||||
reflect.Float32, reflect.Float64:
|
|
||||||
addr = unsafe.Pointer(e.UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported pointer to type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", e.Kind()))
|
|
||||||
}
|
|
||||||
case reflect.Uintptr:
|
|
||||||
addr = unsafe.Pointer(v.Pointer())
|
|
||||||
case reflect.Slice:
|
|
||||||
addr = unsafe.Pointer(v.Index(0).UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", v.Type()))
|
|
||||||
}
|
|
||||||
return addr
|
|
||||||
}
|
|
||||||
|
|
||||||
// PtrOffset takes a pointer offset and returns a GL-compatible pointer.
|
|
||||||
// Useful for functions such as glVertexAttribPointer that take pointer
|
|
||||||
// parameters indicating an offset rather than an absolute memory address.
|
|
||||||
func PtrOffset(offset int) unsafe.Pointer {
|
|
||||||
return unsafe.Pointer(uintptr(offset))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Str takes a null-terminated Go string and returns its GL-compatible address.
|
|
||||||
// This function reaches into Go string storage in an unsafe way so the caller
|
|
||||||
// must ensure the string is not garbage collected.
|
|
||||||
func Str(str string) *uint8 {
|
|
||||||
if !strings.HasSuffix(str, "\x00") {
|
|
||||||
panic("str argument missing null terminator: " + str)
|
|
||||||
}
|
|
||||||
header := (*reflect.StringHeader)(unsafe.Pointer(&str))
|
|
||||||
return (*uint8)(unsafe.Pointer(header.Data))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GoStr takes a null-terminated string returned by OpenGL and constructs a
|
|
||||||
// corresponding Go string.
|
|
||||||
func GoStr(cstr *uint8) string {
|
|
||||||
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strs takes a list of Go strings (with or without null-termination) and
|
|
||||||
// returns their C counterpart.
|
|
||||||
//
|
|
||||||
// The returned free function must be called once you are done using the strings
|
|
||||||
// in order to free the memory.
|
|
||||||
//
|
|
||||||
// If no strings are provided as a parameter this function will panic.
|
|
||||||
func Strs(strs ...string) (cstrs **uint8, free func()) {
|
|
||||||
if len(strs) == 0 {
|
|
||||||
panic("Strs: expected at least 1 string")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate a contiguous array large enough to hold all the strings' contents.
|
|
||||||
n := 0
|
|
||||||
for i := range strs {
|
|
||||||
n += len(strs[i])
|
|
||||||
}
|
|
||||||
data := C.malloc(C.size_t(n))
|
|
||||||
|
|
||||||
// Copy all the strings into data.
|
|
||||||
dataSlice := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
|
|
||||||
Data: uintptr(data),
|
|
||||||
Len: n,
|
|
||||||
Cap: n,
|
|
||||||
}))
|
|
||||||
css := make([]*uint8, len(strs)) // Populated with pointers to each string.
|
|
||||||
offset := 0
|
|
||||||
for i := range strs {
|
|
||||||
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
|
|
||||||
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
|
|
||||||
offset += len(strs[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
return (**uint8)(&css[0]), func() { C.free(data) }
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
type DebugProc func(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message string,
|
|
||||||
userParam unsafe.Pointer)
|
|
||||||
|
|
||||||
var userDebugCallback DebugProc
|
|
||||||
|
|
||||||
//export glowDebugCallback_glcompatibility41
|
|
||||||
func glowDebugCallback_glcompatibility41(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message *uint8,
|
|
||||||
userParam unsafe.Pointer) {
|
|
||||||
if userDebugCallback != nil {
|
|
||||||
userDebugCallback(source, gltype, id, severity, length, GoStr(message), userParam)
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,71 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
// This file implements GlowGetProcAddress for every supported platform. The
|
|
||||||
// correct version is chosen automatically based on build tags:
|
|
||||||
//
|
|
||||||
// windows: WGL
|
|
||||||
// darwin: CGL
|
|
||||||
// linux freebsd: GLX
|
|
||||||
//
|
|
||||||
// Use of EGL instead of the platform's default (listed above) is made possible
|
|
||||||
// via the "egl" build tag.
|
|
||||||
//
|
|
||||||
// It is also possible to install your own function outside this package for
|
|
||||||
// retrieving OpenGL function pointers, to do this see InitWithProcAddrFunc.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
/*
|
|
||||||
#cgo windows CFLAGS: -DTAG_WINDOWS
|
|
||||||
#cgo windows LDFLAGS: -lopengl32
|
|
||||||
#cgo darwin CFLAGS: -DTAG_DARWIN
|
|
||||||
#cgo darwin LDFLAGS: -framework OpenGL
|
|
||||||
#cgo linux freebsd CFLAGS: -DTAG_POSIX
|
|
||||||
#cgo linux freebsd LDFLAGS: -lGL
|
|
||||||
#cgo egl CFLAGS: -DTAG_EGL
|
|
||||||
#cgo egl LDFLAGS: -lEGL
|
|
||||||
// Check the EGL tag first as it takes priority over the platform's default
|
|
||||||
// configuration of WGL/GLX/CGL.
|
|
||||||
#if defined(TAG_EGL)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <EGL/egl.h>
|
|
||||||
void* GlowGetProcAddress_glcompatibility41(const char* name) {
|
|
||||||
return eglGetProcAddress(name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_WINDOWS)
|
|
||||||
#define WIN32_LEAN_AND_MEAN 1
|
|
||||||
#include <windows.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
static HMODULE ogl32dll = NULL;
|
|
||||||
void* GlowGetProcAddress_glcompatibility41(const char* name) {
|
|
||||||
void* pf = wglGetProcAddress((LPCSTR) name);
|
|
||||||
if (pf) {
|
|
||||||
return pf;
|
|
||||||
}
|
|
||||||
if (ogl32dll == NULL) {
|
|
||||||
ogl32dll = LoadLibraryA("opengl32.dll");
|
|
||||||
}
|
|
||||||
return GetProcAddress(ogl32dll, (LPCSTR) name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_DARWIN)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <dlfcn.h>
|
|
||||||
void* GlowGetProcAddress_glcompatibility41(const char* name) {
|
|
||||||
return dlsym(RTLD_DEFAULT, name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_POSIX)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <GL/glx.h>
|
|
||||||
void* GlowGetProcAddress_glcompatibility41(const char* name) {
|
|
||||||
return glXGetProcAddress((const GLubyte *) name);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
func getProcAddress(namea string) unsafe.Pointer {
|
|
||||||
cname := C.CString(namea)
|
|
||||||
defer C.free(unsafe.Pointer(cname))
|
|
||||||
return C.GlowGetProcAddress_glcompatibility41(cname)
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// #include <stdlib.h>
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
// Ptr takes a slice or pointer (to a singular scalar value or the first
|
|
||||||
// element of an array or slice) and returns its GL-compatible address.
|
|
||||||
//
|
|
||||||
// For example:
|
|
||||||
//
|
|
||||||
// var data []uint8
|
|
||||||
// ...
|
|
||||||
// gl.TexImage2D(gl.TEXTURE_2D, ..., gl.UNSIGNED_BYTE, gl.Ptr(&data[0]))
|
|
||||||
func Ptr(data interface{}) unsafe.Pointer {
|
|
||||||
if data == nil {
|
|
||||||
return unsafe.Pointer(nil)
|
|
||||||
}
|
|
||||||
var addr unsafe.Pointer
|
|
||||||
v := reflect.ValueOf(data)
|
|
||||||
switch v.Type().Kind() {
|
|
||||||
case reflect.Ptr:
|
|
||||||
e := v.Elem()
|
|
||||||
switch e.Kind() {
|
|
||||||
case
|
|
||||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
|
||||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
|
||||||
reflect.Float32, reflect.Float64:
|
|
||||||
addr = unsafe.Pointer(e.UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported pointer to type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", e.Kind()))
|
|
||||||
}
|
|
||||||
case reflect.Uintptr:
|
|
||||||
addr = unsafe.Pointer(v.Pointer())
|
|
||||||
case reflect.Slice:
|
|
||||||
addr = unsafe.Pointer(v.Index(0).UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", v.Type()))
|
|
||||||
}
|
|
||||||
return addr
|
|
||||||
}
|
|
||||||
|
|
||||||
// PtrOffset takes a pointer offset and returns a GL-compatible pointer.
|
|
||||||
// Useful for functions such as glVertexAttribPointer that take pointer
|
|
||||||
// parameters indicating an offset rather than an absolute memory address.
|
|
||||||
func PtrOffset(offset int) unsafe.Pointer {
|
|
||||||
return unsafe.Pointer(uintptr(offset))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Str takes a null-terminated Go string and returns its GL-compatible address.
|
|
||||||
// This function reaches into Go string storage in an unsafe way so the caller
|
|
||||||
// must ensure the string is not garbage collected.
|
|
||||||
func Str(str string) *uint8 {
|
|
||||||
if !strings.HasSuffix(str, "\x00") {
|
|
||||||
panic("str argument missing null terminator: " + str)
|
|
||||||
}
|
|
||||||
header := (*reflect.StringHeader)(unsafe.Pointer(&str))
|
|
||||||
return (*uint8)(unsafe.Pointer(header.Data))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GoStr takes a null-terminated string returned by OpenGL and constructs a
|
|
||||||
// corresponding Go string.
|
|
||||||
func GoStr(cstr *uint8) string {
|
|
||||||
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strs takes a list of Go strings (with or without null-termination) and
|
|
||||||
// returns their C counterpart.
|
|
||||||
//
|
|
||||||
// The returned free function must be called once you are done using the strings
|
|
||||||
// in order to free the memory.
|
|
||||||
//
|
|
||||||
// If no strings are provided as a parameter this function will panic.
|
|
||||||
func Strs(strs ...string) (cstrs **uint8, free func()) {
|
|
||||||
if len(strs) == 0 {
|
|
||||||
panic("Strs: expected at least 1 string")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate a contiguous array large enough to hold all the strings' contents.
|
|
||||||
n := 0
|
|
||||||
for i := range strs {
|
|
||||||
n += len(strs[i])
|
|
||||||
}
|
|
||||||
data := C.malloc(C.size_t(n))
|
|
||||||
|
|
||||||
// Copy all the strings into data.
|
|
||||||
dataSlice := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
|
|
||||||
Data: uintptr(data),
|
|
||||||
Len: n,
|
|
||||||
Cap: n,
|
|
||||||
}))
|
|
||||||
css := make([]*uint8, len(strs)) // Populated with pointers to each string.
|
|
||||||
offset := 0
|
|
||||||
for i := range strs {
|
|
||||||
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
|
|
||||||
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
|
|
||||||
offset += len(strs[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
return (**uint8)(&css[0]), func() { C.free(data) }
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
type DebugProc func(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message string,
|
|
||||||
userParam unsafe.Pointer)
|
|
||||||
|
|
||||||
var userDebugCallback DebugProc
|
|
||||||
|
|
||||||
//export glowDebugCallback_glcore41
|
|
||||||
func glowDebugCallback_glcore41(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message *uint8,
|
|
||||||
userParam unsafe.Pointer) {
|
|
||||||
if userDebugCallback != nil {
|
|
||||||
userDebugCallback(source, gltype, id, severity, length, GoStr(message), userParam)
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,71 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
// This file implements GlowGetProcAddress for every supported platform. The
|
|
||||||
// correct version is chosen automatically based on build tags:
|
|
||||||
//
|
|
||||||
// windows: WGL
|
|
||||||
// darwin: CGL
|
|
||||||
// linux freebsd: GLX
|
|
||||||
//
|
|
||||||
// Use of EGL instead of the platform's default (listed above) is made possible
|
|
||||||
// via the "egl" build tag.
|
|
||||||
//
|
|
||||||
// It is also possible to install your own function outside this package for
|
|
||||||
// retrieving OpenGL function pointers, to do this see InitWithProcAddrFunc.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
/*
|
|
||||||
#cgo windows CFLAGS: -DTAG_WINDOWS
|
|
||||||
#cgo windows LDFLAGS: -lopengl32
|
|
||||||
#cgo darwin CFLAGS: -DTAG_DARWIN
|
|
||||||
#cgo darwin LDFLAGS: -framework OpenGL
|
|
||||||
#cgo linux freebsd CFLAGS: -DTAG_POSIX
|
|
||||||
#cgo linux freebsd LDFLAGS: -lGL
|
|
||||||
#cgo egl CFLAGS: -DTAG_EGL
|
|
||||||
#cgo egl LDFLAGS: -lEGL
|
|
||||||
// Check the EGL tag first as it takes priority over the platform's default
|
|
||||||
// configuration of WGL/GLX/CGL.
|
|
||||||
#if defined(TAG_EGL)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <EGL/egl.h>
|
|
||||||
void* GlowGetProcAddress_glcore41(const char* name) {
|
|
||||||
return eglGetProcAddress(name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_WINDOWS)
|
|
||||||
#define WIN32_LEAN_AND_MEAN 1
|
|
||||||
#include <windows.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
static HMODULE ogl32dll = NULL;
|
|
||||||
void* GlowGetProcAddress_glcore41(const char* name) {
|
|
||||||
void* pf = wglGetProcAddress((LPCSTR) name);
|
|
||||||
if (pf) {
|
|
||||||
return pf;
|
|
||||||
}
|
|
||||||
if (ogl32dll == NULL) {
|
|
||||||
ogl32dll = LoadLibraryA("opengl32.dll");
|
|
||||||
}
|
|
||||||
return GetProcAddress(ogl32dll, (LPCSTR) name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_DARWIN)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <dlfcn.h>
|
|
||||||
void* GlowGetProcAddress_glcore41(const char* name) {
|
|
||||||
return dlsym(RTLD_DEFAULT, name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_POSIX)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <GL/glx.h>
|
|
||||||
void* GlowGetProcAddress_glcore41(const char* name) {
|
|
||||||
return glXGetProcAddress((const GLubyte *) name);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
func getProcAddress(namea string) unsafe.Pointer {
|
|
||||||
cname := C.CString(namea)
|
|
||||||
defer C.free(unsafe.Pointer(cname))
|
|
||||||
return C.GlowGetProcAddress_glcore41(cname)
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// #include <stdlib.h>
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
// Ptr takes a slice or pointer (to a singular scalar value or the first
|
|
||||||
// element of an array or slice) and returns its GL-compatible address.
|
|
||||||
//
|
|
||||||
// For example:
|
|
||||||
//
|
|
||||||
// var data []uint8
|
|
||||||
// ...
|
|
||||||
// gl.TexImage2D(gl.TEXTURE_2D, ..., gl.UNSIGNED_BYTE, gl.Ptr(&data[0]))
|
|
||||||
func Ptr(data interface{}) unsafe.Pointer {
|
|
||||||
if data == nil {
|
|
||||||
return unsafe.Pointer(nil)
|
|
||||||
}
|
|
||||||
var addr unsafe.Pointer
|
|
||||||
v := reflect.ValueOf(data)
|
|
||||||
switch v.Type().Kind() {
|
|
||||||
case reflect.Ptr:
|
|
||||||
e := v.Elem()
|
|
||||||
switch e.Kind() {
|
|
||||||
case
|
|
||||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
|
||||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
|
||||||
reflect.Float32, reflect.Float64:
|
|
||||||
addr = unsafe.Pointer(e.UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported pointer to type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", e.Kind()))
|
|
||||||
}
|
|
||||||
case reflect.Uintptr:
|
|
||||||
addr = unsafe.Pointer(v.Pointer())
|
|
||||||
case reflect.Slice:
|
|
||||||
addr = unsafe.Pointer(v.Index(0).UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", v.Type()))
|
|
||||||
}
|
|
||||||
return addr
|
|
||||||
}
|
|
||||||
|
|
||||||
// PtrOffset takes a pointer offset and returns a GL-compatible pointer.
|
|
||||||
// Useful for functions such as glVertexAttribPointer that take pointer
|
|
||||||
// parameters indicating an offset rather than an absolute memory address.
|
|
||||||
func PtrOffset(offset int) unsafe.Pointer {
|
|
||||||
return unsafe.Pointer(uintptr(offset))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Str takes a null-terminated Go string and returns its GL-compatible address.
|
|
||||||
// This function reaches into Go string storage in an unsafe way so the caller
|
|
||||||
// must ensure the string is not garbage collected.
|
|
||||||
func Str(str string) *uint8 {
|
|
||||||
if !strings.HasSuffix(str, "\x00") {
|
|
||||||
panic("str argument missing null terminator: " + str)
|
|
||||||
}
|
|
||||||
header := (*reflect.StringHeader)(unsafe.Pointer(&str))
|
|
||||||
return (*uint8)(unsafe.Pointer(header.Data))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GoStr takes a null-terminated string returned by OpenGL and constructs a
|
|
||||||
// corresponding Go string.
|
|
||||||
func GoStr(cstr *uint8) string {
|
|
||||||
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strs takes a list of Go strings (with or without null-termination) and
|
|
||||||
// returns their C counterpart.
|
|
||||||
//
|
|
||||||
// The returned free function must be called once you are done using the strings
|
|
||||||
// in order to free the memory.
|
|
||||||
//
|
|
||||||
// If no strings are provided as a parameter this function will panic.
|
|
||||||
func Strs(strs ...string) (cstrs **uint8, free func()) {
|
|
||||||
if len(strs) == 0 {
|
|
||||||
panic("Strs: expected at least 1 string")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate a contiguous array large enough to hold all the strings' contents.
|
|
||||||
n := 0
|
|
||||||
for i := range strs {
|
|
||||||
n += len(strs[i])
|
|
||||||
}
|
|
||||||
data := C.malloc(C.size_t(n))
|
|
||||||
|
|
||||||
// Copy all the strings into data.
|
|
||||||
dataSlice := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
|
|
||||||
Data: uintptr(data),
|
|
||||||
Len: n,
|
|
||||||
Cap: n,
|
|
||||||
}))
|
|
||||||
css := make([]*uint8, len(strs)) // Populated with pointers to each string.
|
|
||||||
offset := 0
|
|
||||||
for i := range strs {
|
|
||||||
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
|
|
||||||
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
|
|
||||||
offset += len(strs[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
return (**uint8)(&css[0]), func() { C.free(data) }
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
type DebugProc func(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message string,
|
|
||||||
userParam unsafe.Pointer)
|
|
||||||
|
|
||||||
var userDebugCallback DebugProc
|
|
||||||
|
|
||||||
//export glowDebugCallback_glcompatibility42
|
|
||||||
func glowDebugCallback_glcompatibility42(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message *uint8,
|
|
||||||
userParam unsafe.Pointer) {
|
|
||||||
if userDebugCallback != nil {
|
|
||||||
userDebugCallback(source, gltype, id, severity, length, GoStr(message), userParam)
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,71 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
// This file implements GlowGetProcAddress for every supported platform. The
|
|
||||||
// correct version is chosen automatically based on build tags:
|
|
||||||
//
|
|
||||||
// windows: WGL
|
|
||||||
// darwin: CGL
|
|
||||||
// linux freebsd: GLX
|
|
||||||
//
|
|
||||||
// Use of EGL instead of the platform's default (listed above) is made possible
|
|
||||||
// via the "egl" build tag.
|
|
||||||
//
|
|
||||||
// It is also possible to install your own function outside this package for
|
|
||||||
// retrieving OpenGL function pointers, to do this see InitWithProcAddrFunc.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
/*
|
|
||||||
#cgo windows CFLAGS: -DTAG_WINDOWS
|
|
||||||
#cgo windows LDFLAGS: -lopengl32
|
|
||||||
#cgo darwin CFLAGS: -DTAG_DARWIN
|
|
||||||
#cgo darwin LDFLAGS: -framework OpenGL
|
|
||||||
#cgo linux freebsd CFLAGS: -DTAG_POSIX
|
|
||||||
#cgo linux freebsd LDFLAGS: -lGL
|
|
||||||
#cgo egl CFLAGS: -DTAG_EGL
|
|
||||||
#cgo egl LDFLAGS: -lEGL
|
|
||||||
// Check the EGL tag first as it takes priority over the platform's default
|
|
||||||
// configuration of WGL/GLX/CGL.
|
|
||||||
#if defined(TAG_EGL)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <EGL/egl.h>
|
|
||||||
void* GlowGetProcAddress_glcompatibility42(const char* name) {
|
|
||||||
return eglGetProcAddress(name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_WINDOWS)
|
|
||||||
#define WIN32_LEAN_AND_MEAN 1
|
|
||||||
#include <windows.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
static HMODULE ogl32dll = NULL;
|
|
||||||
void* GlowGetProcAddress_glcompatibility42(const char* name) {
|
|
||||||
void* pf = wglGetProcAddress((LPCSTR) name);
|
|
||||||
if (pf) {
|
|
||||||
return pf;
|
|
||||||
}
|
|
||||||
if (ogl32dll == NULL) {
|
|
||||||
ogl32dll = LoadLibraryA("opengl32.dll");
|
|
||||||
}
|
|
||||||
return GetProcAddress(ogl32dll, (LPCSTR) name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_DARWIN)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <dlfcn.h>
|
|
||||||
void* GlowGetProcAddress_glcompatibility42(const char* name) {
|
|
||||||
return dlsym(RTLD_DEFAULT, name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_POSIX)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <GL/glx.h>
|
|
||||||
void* GlowGetProcAddress_glcompatibility42(const char* name) {
|
|
||||||
return glXGetProcAddress((const GLubyte *) name);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
func getProcAddress(namea string) unsafe.Pointer {
|
|
||||||
cname := C.CString(namea)
|
|
||||||
defer C.free(unsafe.Pointer(cname))
|
|
||||||
return C.GlowGetProcAddress_glcompatibility42(cname)
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// #include <stdlib.h>
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
// Ptr takes a slice or pointer (to a singular scalar value or the first
|
|
||||||
// element of an array or slice) and returns its GL-compatible address.
|
|
||||||
//
|
|
||||||
// For example:
|
|
||||||
//
|
|
||||||
// var data []uint8
|
|
||||||
// ...
|
|
||||||
// gl.TexImage2D(gl.TEXTURE_2D, ..., gl.UNSIGNED_BYTE, gl.Ptr(&data[0]))
|
|
||||||
func Ptr(data interface{}) unsafe.Pointer {
|
|
||||||
if data == nil {
|
|
||||||
return unsafe.Pointer(nil)
|
|
||||||
}
|
|
||||||
var addr unsafe.Pointer
|
|
||||||
v := reflect.ValueOf(data)
|
|
||||||
switch v.Type().Kind() {
|
|
||||||
case reflect.Ptr:
|
|
||||||
e := v.Elem()
|
|
||||||
switch e.Kind() {
|
|
||||||
case
|
|
||||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
|
||||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
|
||||||
reflect.Float32, reflect.Float64:
|
|
||||||
addr = unsafe.Pointer(e.UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported pointer to type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", e.Kind()))
|
|
||||||
}
|
|
||||||
case reflect.Uintptr:
|
|
||||||
addr = unsafe.Pointer(v.Pointer())
|
|
||||||
case reflect.Slice:
|
|
||||||
addr = unsafe.Pointer(v.Index(0).UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", v.Type()))
|
|
||||||
}
|
|
||||||
return addr
|
|
||||||
}
|
|
||||||
|
|
||||||
// PtrOffset takes a pointer offset and returns a GL-compatible pointer.
|
|
||||||
// Useful for functions such as glVertexAttribPointer that take pointer
|
|
||||||
// parameters indicating an offset rather than an absolute memory address.
|
|
||||||
func PtrOffset(offset int) unsafe.Pointer {
|
|
||||||
return unsafe.Pointer(uintptr(offset))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Str takes a null-terminated Go string and returns its GL-compatible address.
|
|
||||||
// This function reaches into Go string storage in an unsafe way so the caller
|
|
||||||
// must ensure the string is not garbage collected.
|
|
||||||
func Str(str string) *uint8 {
|
|
||||||
if !strings.HasSuffix(str, "\x00") {
|
|
||||||
panic("str argument missing null terminator: " + str)
|
|
||||||
}
|
|
||||||
header := (*reflect.StringHeader)(unsafe.Pointer(&str))
|
|
||||||
return (*uint8)(unsafe.Pointer(header.Data))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GoStr takes a null-terminated string returned by OpenGL and constructs a
|
|
||||||
// corresponding Go string.
|
|
||||||
func GoStr(cstr *uint8) string {
|
|
||||||
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strs takes a list of Go strings (with or without null-termination) and
|
|
||||||
// returns their C counterpart.
|
|
||||||
//
|
|
||||||
// The returned free function must be called once you are done using the strings
|
|
||||||
// in order to free the memory.
|
|
||||||
//
|
|
||||||
// If no strings are provided as a parameter this function will panic.
|
|
||||||
func Strs(strs ...string) (cstrs **uint8, free func()) {
|
|
||||||
if len(strs) == 0 {
|
|
||||||
panic("Strs: expected at least 1 string")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate a contiguous array large enough to hold all the strings' contents.
|
|
||||||
n := 0
|
|
||||||
for i := range strs {
|
|
||||||
n += len(strs[i])
|
|
||||||
}
|
|
||||||
data := C.malloc(C.size_t(n))
|
|
||||||
|
|
||||||
// Copy all the strings into data.
|
|
||||||
dataSlice := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
|
|
||||||
Data: uintptr(data),
|
|
||||||
Len: n,
|
|
||||||
Cap: n,
|
|
||||||
}))
|
|
||||||
css := make([]*uint8, len(strs)) // Populated with pointers to each string.
|
|
||||||
offset := 0
|
|
||||||
for i := range strs {
|
|
||||||
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
|
|
||||||
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
|
|
||||||
offset += len(strs[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
return (**uint8)(&css[0]), func() { C.free(data) }
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
type DebugProc func(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message string,
|
|
||||||
userParam unsafe.Pointer)
|
|
||||||
|
|
||||||
var userDebugCallback DebugProc
|
|
||||||
|
|
||||||
//export glowDebugCallback_glcore42
|
|
||||||
func glowDebugCallback_glcore42(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message *uint8,
|
|
||||||
userParam unsafe.Pointer) {
|
|
||||||
if userDebugCallback != nil {
|
|
||||||
userDebugCallback(source, gltype, id, severity, length, GoStr(message), userParam)
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,71 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
// This file implements GlowGetProcAddress for every supported platform. The
|
|
||||||
// correct version is chosen automatically based on build tags:
|
|
||||||
//
|
|
||||||
// windows: WGL
|
|
||||||
// darwin: CGL
|
|
||||||
// linux freebsd: GLX
|
|
||||||
//
|
|
||||||
// Use of EGL instead of the platform's default (listed above) is made possible
|
|
||||||
// via the "egl" build tag.
|
|
||||||
//
|
|
||||||
// It is also possible to install your own function outside this package for
|
|
||||||
// retrieving OpenGL function pointers, to do this see InitWithProcAddrFunc.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
/*
|
|
||||||
#cgo windows CFLAGS: -DTAG_WINDOWS
|
|
||||||
#cgo windows LDFLAGS: -lopengl32
|
|
||||||
#cgo darwin CFLAGS: -DTAG_DARWIN
|
|
||||||
#cgo darwin LDFLAGS: -framework OpenGL
|
|
||||||
#cgo linux freebsd CFLAGS: -DTAG_POSIX
|
|
||||||
#cgo linux freebsd LDFLAGS: -lGL
|
|
||||||
#cgo egl CFLAGS: -DTAG_EGL
|
|
||||||
#cgo egl LDFLAGS: -lEGL
|
|
||||||
// Check the EGL tag first as it takes priority over the platform's default
|
|
||||||
// configuration of WGL/GLX/CGL.
|
|
||||||
#if defined(TAG_EGL)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <EGL/egl.h>
|
|
||||||
void* GlowGetProcAddress_glcore42(const char* name) {
|
|
||||||
return eglGetProcAddress(name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_WINDOWS)
|
|
||||||
#define WIN32_LEAN_AND_MEAN 1
|
|
||||||
#include <windows.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
static HMODULE ogl32dll = NULL;
|
|
||||||
void* GlowGetProcAddress_glcore42(const char* name) {
|
|
||||||
void* pf = wglGetProcAddress((LPCSTR) name);
|
|
||||||
if (pf) {
|
|
||||||
return pf;
|
|
||||||
}
|
|
||||||
if (ogl32dll == NULL) {
|
|
||||||
ogl32dll = LoadLibraryA("opengl32.dll");
|
|
||||||
}
|
|
||||||
return GetProcAddress(ogl32dll, (LPCSTR) name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_DARWIN)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <dlfcn.h>
|
|
||||||
void* GlowGetProcAddress_glcore42(const char* name) {
|
|
||||||
return dlsym(RTLD_DEFAULT, name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_POSIX)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <GL/glx.h>
|
|
||||||
void* GlowGetProcAddress_glcore42(const char* name) {
|
|
||||||
return glXGetProcAddress((const GLubyte *) name);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
func getProcAddress(namea string) unsafe.Pointer {
|
|
||||||
cname := C.CString(namea)
|
|
||||||
defer C.free(unsafe.Pointer(cname))
|
|
||||||
return C.GlowGetProcAddress_glcore42(cname)
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// #include <stdlib.h>
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
// Ptr takes a slice or pointer (to a singular scalar value or the first
|
|
||||||
// element of an array or slice) and returns its GL-compatible address.
|
|
||||||
//
|
|
||||||
// For example:
|
|
||||||
//
|
|
||||||
// var data []uint8
|
|
||||||
// ...
|
|
||||||
// gl.TexImage2D(gl.TEXTURE_2D, ..., gl.UNSIGNED_BYTE, gl.Ptr(&data[0]))
|
|
||||||
func Ptr(data interface{}) unsafe.Pointer {
|
|
||||||
if data == nil {
|
|
||||||
return unsafe.Pointer(nil)
|
|
||||||
}
|
|
||||||
var addr unsafe.Pointer
|
|
||||||
v := reflect.ValueOf(data)
|
|
||||||
switch v.Type().Kind() {
|
|
||||||
case reflect.Ptr:
|
|
||||||
e := v.Elem()
|
|
||||||
switch e.Kind() {
|
|
||||||
case
|
|
||||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
|
||||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
|
||||||
reflect.Float32, reflect.Float64:
|
|
||||||
addr = unsafe.Pointer(e.UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported pointer to type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", e.Kind()))
|
|
||||||
}
|
|
||||||
case reflect.Uintptr:
|
|
||||||
addr = unsafe.Pointer(v.Pointer())
|
|
||||||
case reflect.Slice:
|
|
||||||
addr = unsafe.Pointer(v.Index(0).UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", v.Type()))
|
|
||||||
}
|
|
||||||
return addr
|
|
||||||
}
|
|
||||||
|
|
||||||
// PtrOffset takes a pointer offset and returns a GL-compatible pointer.
|
|
||||||
// Useful for functions such as glVertexAttribPointer that take pointer
|
|
||||||
// parameters indicating an offset rather than an absolute memory address.
|
|
||||||
func PtrOffset(offset int) unsafe.Pointer {
|
|
||||||
return unsafe.Pointer(uintptr(offset))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Str takes a null-terminated Go string and returns its GL-compatible address.
|
|
||||||
// This function reaches into Go string storage in an unsafe way so the caller
|
|
||||||
// must ensure the string is not garbage collected.
|
|
||||||
func Str(str string) *uint8 {
|
|
||||||
if !strings.HasSuffix(str, "\x00") {
|
|
||||||
panic("str argument missing null terminator: " + str)
|
|
||||||
}
|
|
||||||
header := (*reflect.StringHeader)(unsafe.Pointer(&str))
|
|
||||||
return (*uint8)(unsafe.Pointer(header.Data))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GoStr takes a null-terminated string returned by OpenGL and constructs a
|
|
||||||
// corresponding Go string.
|
|
||||||
func GoStr(cstr *uint8) string {
|
|
||||||
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strs takes a list of Go strings (with or without null-termination) and
|
|
||||||
// returns their C counterpart.
|
|
||||||
//
|
|
||||||
// The returned free function must be called once you are done using the strings
|
|
||||||
// in order to free the memory.
|
|
||||||
//
|
|
||||||
// If no strings are provided as a parameter this function will panic.
|
|
||||||
func Strs(strs ...string) (cstrs **uint8, free func()) {
|
|
||||||
if len(strs) == 0 {
|
|
||||||
panic("Strs: expected at least 1 string")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate a contiguous array large enough to hold all the strings' contents.
|
|
||||||
n := 0
|
|
||||||
for i := range strs {
|
|
||||||
n += len(strs[i])
|
|
||||||
}
|
|
||||||
data := C.malloc(C.size_t(n))
|
|
||||||
|
|
||||||
// Copy all the strings into data.
|
|
||||||
dataSlice := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
|
|
||||||
Data: uintptr(data),
|
|
||||||
Len: n,
|
|
||||||
Cap: n,
|
|
||||||
}))
|
|
||||||
css := make([]*uint8, len(strs)) // Populated with pointers to each string.
|
|
||||||
offset := 0
|
|
||||||
for i := range strs {
|
|
||||||
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
|
|
||||||
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
|
|
||||||
offset += len(strs[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
return (**uint8)(&css[0]), func() { C.free(data) }
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
type DebugProc func(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message string,
|
|
||||||
userParam unsafe.Pointer)
|
|
||||||
|
|
||||||
var userDebugCallback DebugProc
|
|
||||||
|
|
||||||
//export glowDebugCallback_glcompatibility43
|
|
||||||
func glowDebugCallback_glcompatibility43(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message *uint8,
|
|
||||||
userParam unsafe.Pointer) {
|
|
||||||
if userDebugCallback != nil {
|
|
||||||
userDebugCallback(source, gltype, id, severity, length, GoStr(message), userParam)
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,71 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
// This file implements GlowGetProcAddress for every supported platform. The
|
|
||||||
// correct version is chosen automatically based on build tags:
|
|
||||||
//
|
|
||||||
// windows: WGL
|
|
||||||
// darwin: CGL
|
|
||||||
// linux freebsd: GLX
|
|
||||||
//
|
|
||||||
// Use of EGL instead of the platform's default (listed above) is made possible
|
|
||||||
// via the "egl" build tag.
|
|
||||||
//
|
|
||||||
// It is also possible to install your own function outside this package for
|
|
||||||
// retrieving OpenGL function pointers, to do this see InitWithProcAddrFunc.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
/*
|
|
||||||
#cgo windows CFLAGS: -DTAG_WINDOWS
|
|
||||||
#cgo windows LDFLAGS: -lopengl32
|
|
||||||
#cgo darwin CFLAGS: -DTAG_DARWIN
|
|
||||||
#cgo darwin LDFLAGS: -framework OpenGL
|
|
||||||
#cgo linux freebsd CFLAGS: -DTAG_POSIX
|
|
||||||
#cgo linux freebsd LDFLAGS: -lGL
|
|
||||||
#cgo egl CFLAGS: -DTAG_EGL
|
|
||||||
#cgo egl LDFLAGS: -lEGL
|
|
||||||
// Check the EGL tag first as it takes priority over the platform's default
|
|
||||||
// configuration of WGL/GLX/CGL.
|
|
||||||
#if defined(TAG_EGL)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <EGL/egl.h>
|
|
||||||
void* GlowGetProcAddress_glcompatibility43(const char* name) {
|
|
||||||
return eglGetProcAddress(name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_WINDOWS)
|
|
||||||
#define WIN32_LEAN_AND_MEAN 1
|
|
||||||
#include <windows.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
static HMODULE ogl32dll = NULL;
|
|
||||||
void* GlowGetProcAddress_glcompatibility43(const char* name) {
|
|
||||||
void* pf = wglGetProcAddress((LPCSTR) name);
|
|
||||||
if (pf) {
|
|
||||||
return pf;
|
|
||||||
}
|
|
||||||
if (ogl32dll == NULL) {
|
|
||||||
ogl32dll = LoadLibraryA("opengl32.dll");
|
|
||||||
}
|
|
||||||
return GetProcAddress(ogl32dll, (LPCSTR) name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_DARWIN)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <dlfcn.h>
|
|
||||||
void* GlowGetProcAddress_glcompatibility43(const char* name) {
|
|
||||||
return dlsym(RTLD_DEFAULT, name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_POSIX)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <GL/glx.h>
|
|
||||||
void* GlowGetProcAddress_glcompatibility43(const char* name) {
|
|
||||||
return glXGetProcAddress((const GLubyte *) name);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
func getProcAddress(namea string) unsafe.Pointer {
|
|
||||||
cname := C.CString(namea)
|
|
||||||
defer C.free(unsafe.Pointer(cname))
|
|
||||||
return C.GlowGetProcAddress_glcompatibility43(cname)
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// #include <stdlib.h>
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
// Ptr takes a slice or pointer (to a singular scalar value or the first
|
|
||||||
// element of an array or slice) and returns its GL-compatible address.
|
|
||||||
//
|
|
||||||
// For example:
|
|
||||||
//
|
|
||||||
// var data []uint8
|
|
||||||
// ...
|
|
||||||
// gl.TexImage2D(gl.TEXTURE_2D, ..., gl.UNSIGNED_BYTE, gl.Ptr(&data[0]))
|
|
||||||
func Ptr(data interface{}) unsafe.Pointer {
|
|
||||||
if data == nil {
|
|
||||||
return unsafe.Pointer(nil)
|
|
||||||
}
|
|
||||||
var addr unsafe.Pointer
|
|
||||||
v := reflect.ValueOf(data)
|
|
||||||
switch v.Type().Kind() {
|
|
||||||
case reflect.Ptr:
|
|
||||||
e := v.Elem()
|
|
||||||
switch e.Kind() {
|
|
||||||
case
|
|
||||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
|
||||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
|
||||||
reflect.Float32, reflect.Float64:
|
|
||||||
addr = unsafe.Pointer(e.UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported pointer to type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", e.Kind()))
|
|
||||||
}
|
|
||||||
case reflect.Uintptr:
|
|
||||||
addr = unsafe.Pointer(v.Pointer())
|
|
||||||
case reflect.Slice:
|
|
||||||
addr = unsafe.Pointer(v.Index(0).UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", v.Type()))
|
|
||||||
}
|
|
||||||
return addr
|
|
||||||
}
|
|
||||||
|
|
||||||
// PtrOffset takes a pointer offset and returns a GL-compatible pointer.
|
|
||||||
// Useful for functions such as glVertexAttribPointer that take pointer
|
|
||||||
// parameters indicating an offset rather than an absolute memory address.
|
|
||||||
func PtrOffset(offset int) unsafe.Pointer {
|
|
||||||
return unsafe.Pointer(uintptr(offset))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Str takes a null-terminated Go string and returns its GL-compatible address.
|
|
||||||
// This function reaches into Go string storage in an unsafe way so the caller
|
|
||||||
// must ensure the string is not garbage collected.
|
|
||||||
func Str(str string) *uint8 {
|
|
||||||
if !strings.HasSuffix(str, "\x00") {
|
|
||||||
panic("str argument missing null terminator: " + str)
|
|
||||||
}
|
|
||||||
header := (*reflect.StringHeader)(unsafe.Pointer(&str))
|
|
||||||
return (*uint8)(unsafe.Pointer(header.Data))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GoStr takes a null-terminated string returned by OpenGL and constructs a
|
|
||||||
// corresponding Go string.
|
|
||||||
func GoStr(cstr *uint8) string {
|
|
||||||
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strs takes a list of Go strings (with or without null-termination) and
|
|
||||||
// returns their C counterpart.
|
|
||||||
//
|
|
||||||
// The returned free function must be called once you are done using the strings
|
|
||||||
// in order to free the memory.
|
|
||||||
//
|
|
||||||
// If no strings are provided as a parameter this function will panic.
|
|
||||||
func Strs(strs ...string) (cstrs **uint8, free func()) {
|
|
||||||
if len(strs) == 0 {
|
|
||||||
panic("Strs: expected at least 1 string")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate a contiguous array large enough to hold all the strings' contents.
|
|
||||||
n := 0
|
|
||||||
for i := range strs {
|
|
||||||
n += len(strs[i])
|
|
||||||
}
|
|
||||||
data := C.malloc(C.size_t(n))
|
|
||||||
|
|
||||||
// Copy all the strings into data.
|
|
||||||
dataSlice := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
|
|
||||||
Data: uintptr(data),
|
|
||||||
Len: n,
|
|
||||||
Cap: n,
|
|
||||||
}))
|
|
||||||
css := make([]*uint8, len(strs)) // Populated with pointers to each string.
|
|
||||||
offset := 0
|
|
||||||
for i := range strs {
|
|
||||||
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
|
|
||||||
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
|
|
||||||
offset += len(strs[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
return (**uint8)(&css[0]), func() { C.free(data) }
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
type DebugProc func(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message string,
|
|
||||||
userParam unsafe.Pointer)
|
|
||||||
|
|
||||||
var userDebugCallback DebugProc
|
|
||||||
|
|
||||||
//export glowDebugCallback_glcore43
|
|
||||||
func glowDebugCallback_glcore43(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message *uint8,
|
|
||||||
userParam unsafe.Pointer) {
|
|
||||||
if userDebugCallback != nil {
|
|
||||||
userDebugCallback(source, gltype, id, severity, length, GoStr(message), userParam)
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,71 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
// This file implements GlowGetProcAddress for every supported platform. The
|
|
||||||
// correct version is chosen automatically based on build tags:
|
|
||||||
//
|
|
||||||
// windows: WGL
|
|
||||||
// darwin: CGL
|
|
||||||
// linux freebsd: GLX
|
|
||||||
//
|
|
||||||
// Use of EGL instead of the platform's default (listed above) is made possible
|
|
||||||
// via the "egl" build tag.
|
|
||||||
//
|
|
||||||
// It is also possible to install your own function outside this package for
|
|
||||||
// retrieving OpenGL function pointers, to do this see InitWithProcAddrFunc.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
/*
|
|
||||||
#cgo windows CFLAGS: -DTAG_WINDOWS
|
|
||||||
#cgo windows LDFLAGS: -lopengl32
|
|
||||||
#cgo darwin CFLAGS: -DTAG_DARWIN
|
|
||||||
#cgo darwin LDFLAGS: -framework OpenGL
|
|
||||||
#cgo linux freebsd CFLAGS: -DTAG_POSIX
|
|
||||||
#cgo linux freebsd LDFLAGS: -lGL
|
|
||||||
#cgo egl CFLAGS: -DTAG_EGL
|
|
||||||
#cgo egl LDFLAGS: -lEGL
|
|
||||||
// Check the EGL tag first as it takes priority over the platform's default
|
|
||||||
// configuration of WGL/GLX/CGL.
|
|
||||||
#if defined(TAG_EGL)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <EGL/egl.h>
|
|
||||||
void* GlowGetProcAddress_glcore43(const char* name) {
|
|
||||||
return eglGetProcAddress(name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_WINDOWS)
|
|
||||||
#define WIN32_LEAN_AND_MEAN 1
|
|
||||||
#include <windows.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
static HMODULE ogl32dll = NULL;
|
|
||||||
void* GlowGetProcAddress_glcore43(const char* name) {
|
|
||||||
void* pf = wglGetProcAddress((LPCSTR) name);
|
|
||||||
if (pf) {
|
|
||||||
return pf;
|
|
||||||
}
|
|
||||||
if (ogl32dll == NULL) {
|
|
||||||
ogl32dll = LoadLibraryA("opengl32.dll");
|
|
||||||
}
|
|
||||||
return GetProcAddress(ogl32dll, (LPCSTR) name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_DARWIN)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <dlfcn.h>
|
|
||||||
void* GlowGetProcAddress_glcore43(const char* name) {
|
|
||||||
return dlsym(RTLD_DEFAULT, name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_POSIX)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <GL/glx.h>
|
|
||||||
void* GlowGetProcAddress_glcore43(const char* name) {
|
|
||||||
return glXGetProcAddress((const GLubyte *) name);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
func getProcAddress(namea string) unsafe.Pointer {
|
|
||||||
cname := C.CString(namea)
|
|
||||||
defer C.free(unsafe.Pointer(cname))
|
|
||||||
return C.GlowGetProcAddress_glcore43(cname)
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// #include <stdlib.h>
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
// Ptr takes a slice or pointer (to a singular scalar value or the first
|
|
||||||
// element of an array or slice) and returns its GL-compatible address.
|
|
||||||
//
|
|
||||||
// For example:
|
|
||||||
//
|
|
||||||
// var data []uint8
|
|
||||||
// ...
|
|
||||||
// gl.TexImage2D(gl.TEXTURE_2D, ..., gl.UNSIGNED_BYTE, gl.Ptr(&data[0]))
|
|
||||||
func Ptr(data interface{}) unsafe.Pointer {
|
|
||||||
if data == nil {
|
|
||||||
return unsafe.Pointer(nil)
|
|
||||||
}
|
|
||||||
var addr unsafe.Pointer
|
|
||||||
v := reflect.ValueOf(data)
|
|
||||||
switch v.Type().Kind() {
|
|
||||||
case reflect.Ptr:
|
|
||||||
e := v.Elem()
|
|
||||||
switch e.Kind() {
|
|
||||||
case
|
|
||||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
|
||||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
|
||||||
reflect.Float32, reflect.Float64:
|
|
||||||
addr = unsafe.Pointer(e.UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported pointer to type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", e.Kind()))
|
|
||||||
}
|
|
||||||
case reflect.Uintptr:
|
|
||||||
addr = unsafe.Pointer(v.Pointer())
|
|
||||||
case reflect.Slice:
|
|
||||||
addr = unsafe.Pointer(v.Index(0).UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", v.Type()))
|
|
||||||
}
|
|
||||||
return addr
|
|
||||||
}
|
|
||||||
|
|
||||||
// PtrOffset takes a pointer offset and returns a GL-compatible pointer.
|
|
||||||
// Useful for functions such as glVertexAttribPointer that take pointer
|
|
||||||
// parameters indicating an offset rather than an absolute memory address.
|
|
||||||
func PtrOffset(offset int) unsafe.Pointer {
|
|
||||||
return unsafe.Pointer(uintptr(offset))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Str takes a null-terminated Go string and returns its GL-compatible address.
|
|
||||||
// This function reaches into Go string storage in an unsafe way so the caller
|
|
||||||
// must ensure the string is not garbage collected.
|
|
||||||
func Str(str string) *uint8 {
|
|
||||||
if !strings.HasSuffix(str, "\x00") {
|
|
||||||
panic("str argument missing null terminator: " + str)
|
|
||||||
}
|
|
||||||
header := (*reflect.StringHeader)(unsafe.Pointer(&str))
|
|
||||||
return (*uint8)(unsafe.Pointer(header.Data))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GoStr takes a null-terminated string returned by OpenGL and constructs a
|
|
||||||
// corresponding Go string.
|
|
||||||
func GoStr(cstr *uint8) string {
|
|
||||||
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strs takes a list of Go strings (with or without null-termination) and
|
|
||||||
// returns their C counterpart.
|
|
||||||
//
|
|
||||||
// The returned free function must be called once you are done using the strings
|
|
||||||
// in order to free the memory.
|
|
||||||
//
|
|
||||||
// If no strings are provided as a parameter this function will panic.
|
|
||||||
func Strs(strs ...string) (cstrs **uint8, free func()) {
|
|
||||||
if len(strs) == 0 {
|
|
||||||
panic("Strs: expected at least 1 string")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate a contiguous array large enough to hold all the strings' contents.
|
|
||||||
n := 0
|
|
||||||
for i := range strs {
|
|
||||||
n += len(strs[i])
|
|
||||||
}
|
|
||||||
data := C.malloc(C.size_t(n))
|
|
||||||
|
|
||||||
// Copy all the strings into data.
|
|
||||||
dataSlice := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
|
|
||||||
Data: uintptr(data),
|
|
||||||
Len: n,
|
|
||||||
Cap: n,
|
|
||||||
}))
|
|
||||||
css := make([]*uint8, len(strs)) // Populated with pointers to each string.
|
|
||||||
offset := 0
|
|
||||||
for i := range strs {
|
|
||||||
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
|
|
||||||
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
|
|
||||||
offset += len(strs[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
return (**uint8)(&css[0]), func() { C.free(data) }
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
type DebugProc func(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message string,
|
|
||||||
userParam unsafe.Pointer)
|
|
||||||
|
|
||||||
var userDebugCallback DebugProc
|
|
||||||
|
|
||||||
//export glowDebugCallback_glcompatibility44
|
|
||||||
func glowDebugCallback_glcompatibility44(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message *uint8,
|
|
||||||
userParam unsafe.Pointer) {
|
|
||||||
if userDebugCallback != nil {
|
|
||||||
userDebugCallback(source, gltype, id, severity, length, GoStr(message), userParam)
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,71 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
// This file implements GlowGetProcAddress for every supported platform. The
|
|
||||||
// correct version is chosen automatically based on build tags:
|
|
||||||
//
|
|
||||||
// windows: WGL
|
|
||||||
// darwin: CGL
|
|
||||||
// linux freebsd: GLX
|
|
||||||
//
|
|
||||||
// Use of EGL instead of the platform's default (listed above) is made possible
|
|
||||||
// via the "egl" build tag.
|
|
||||||
//
|
|
||||||
// It is also possible to install your own function outside this package for
|
|
||||||
// retrieving OpenGL function pointers, to do this see InitWithProcAddrFunc.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
/*
|
|
||||||
#cgo windows CFLAGS: -DTAG_WINDOWS
|
|
||||||
#cgo windows LDFLAGS: -lopengl32
|
|
||||||
#cgo darwin CFLAGS: -DTAG_DARWIN
|
|
||||||
#cgo darwin LDFLAGS: -framework OpenGL
|
|
||||||
#cgo linux freebsd CFLAGS: -DTAG_POSIX
|
|
||||||
#cgo linux freebsd LDFLAGS: -lGL
|
|
||||||
#cgo egl CFLAGS: -DTAG_EGL
|
|
||||||
#cgo egl LDFLAGS: -lEGL
|
|
||||||
// Check the EGL tag first as it takes priority over the platform's default
|
|
||||||
// configuration of WGL/GLX/CGL.
|
|
||||||
#if defined(TAG_EGL)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <EGL/egl.h>
|
|
||||||
void* GlowGetProcAddress_glcompatibility44(const char* name) {
|
|
||||||
return eglGetProcAddress(name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_WINDOWS)
|
|
||||||
#define WIN32_LEAN_AND_MEAN 1
|
|
||||||
#include <windows.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
static HMODULE ogl32dll = NULL;
|
|
||||||
void* GlowGetProcAddress_glcompatibility44(const char* name) {
|
|
||||||
void* pf = wglGetProcAddress((LPCSTR) name);
|
|
||||||
if (pf) {
|
|
||||||
return pf;
|
|
||||||
}
|
|
||||||
if (ogl32dll == NULL) {
|
|
||||||
ogl32dll = LoadLibraryA("opengl32.dll");
|
|
||||||
}
|
|
||||||
return GetProcAddress(ogl32dll, (LPCSTR) name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_DARWIN)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <dlfcn.h>
|
|
||||||
void* GlowGetProcAddress_glcompatibility44(const char* name) {
|
|
||||||
return dlsym(RTLD_DEFAULT, name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_POSIX)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <GL/glx.h>
|
|
||||||
void* GlowGetProcAddress_glcompatibility44(const char* name) {
|
|
||||||
return glXGetProcAddress((const GLubyte *) name);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
func getProcAddress(namea string) unsafe.Pointer {
|
|
||||||
cname := C.CString(namea)
|
|
||||||
defer C.free(unsafe.Pointer(cname))
|
|
||||||
return C.GlowGetProcAddress_glcompatibility44(cname)
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// #include <stdlib.h>
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
// Ptr takes a slice or pointer (to a singular scalar value or the first
|
|
||||||
// element of an array or slice) and returns its GL-compatible address.
|
|
||||||
//
|
|
||||||
// For example:
|
|
||||||
//
|
|
||||||
// var data []uint8
|
|
||||||
// ...
|
|
||||||
// gl.TexImage2D(gl.TEXTURE_2D, ..., gl.UNSIGNED_BYTE, gl.Ptr(&data[0]))
|
|
||||||
func Ptr(data interface{}) unsafe.Pointer {
|
|
||||||
if data == nil {
|
|
||||||
return unsafe.Pointer(nil)
|
|
||||||
}
|
|
||||||
var addr unsafe.Pointer
|
|
||||||
v := reflect.ValueOf(data)
|
|
||||||
switch v.Type().Kind() {
|
|
||||||
case reflect.Ptr:
|
|
||||||
e := v.Elem()
|
|
||||||
switch e.Kind() {
|
|
||||||
case
|
|
||||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
|
||||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
|
||||||
reflect.Float32, reflect.Float64:
|
|
||||||
addr = unsafe.Pointer(e.UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported pointer to type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", e.Kind()))
|
|
||||||
}
|
|
||||||
case reflect.Uintptr:
|
|
||||||
addr = unsafe.Pointer(v.Pointer())
|
|
||||||
case reflect.Slice:
|
|
||||||
addr = unsafe.Pointer(v.Index(0).UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", v.Type()))
|
|
||||||
}
|
|
||||||
return addr
|
|
||||||
}
|
|
||||||
|
|
||||||
// PtrOffset takes a pointer offset and returns a GL-compatible pointer.
|
|
||||||
// Useful for functions such as glVertexAttribPointer that take pointer
|
|
||||||
// parameters indicating an offset rather than an absolute memory address.
|
|
||||||
func PtrOffset(offset int) unsafe.Pointer {
|
|
||||||
return unsafe.Pointer(uintptr(offset))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Str takes a null-terminated Go string and returns its GL-compatible address.
|
|
||||||
// This function reaches into Go string storage in an unsafe way so the caller
|
|
||||||
// must ensure the string is not garbage collected.
|
|
||||||
func Str(str string) *uint8 {
|
|
||||||
if !strings.HasSuffix(str, "\x00") {
|
|
||||||
panic("str argument missing null terminator: " + str)
|
|
||||||
}
|
|
||||||
header := (*reflect.StringHeader)(unsafe.Pointer(&str))
|
|
||||||
return (*uint8)(unsafe.Pointer(header.Data))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GoStr takes a null-terminated string returned by OpenGL and constructs a
|
|
||||||
// corresponding Go string.
|
|
||||||
func GoStr(cstr *uint8) string {
|
|
||||||
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strs takes a list of Go strings (with or without null-termination) and
|
|
||||||
// returns their C counterpart.
|
|
||||||
//
|
|
||||||
// The returned free function must be called once you are done using the strings
|
|
||||||
// in order to free the memory.
|
|
||||||
//
|
|
||||||
// If no strings are provided as a parameter this function will panic.
|
|
||||||
func Strs(strs ...string) (cstrs **uint8, free func()) {
|
|
||||||
if len(strs) == 0 {
|
|
||||||
panic("Strs: expected at least 1 string")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate a contiguous array large enough to hold all the strings' contents.
|
|
||||||
n := 0
|
|
||||||
for i := range strs {
|
|
||||||
n += len(strs[i])
|
|
||||||
}
|
|
||||||
data := C.malloc(C.size_t(n))
|
|
||||||
|
|
||||||
// Copy all the strings into data.
|
|
||||||
dataSlice := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
|
|
||||||
Data: uintptr(data),
|
|
||||||
Len: n,
|
|
||||||
Cap: n,
|
|
||||||
}))
|
|
||||||
css := make([]*uint8, len(strs)) // Populated with pointers to each string.
|
|
||||||
offset := 0
|
|
||||||
for i := range strs {
|
|
||||||
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
|
|
||||||
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
|
|
||||||
offset += len(strs[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
return (**uint8)(&css[0]), func() { C.free(data) }
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
type DebugProc func(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message string,
|
|
||||||
userParam unsafe.Pointer)
|
|
||||||
|
|
||||||
var userDebugCallback DebugProc
|
|
||||||
|
|
||||||
//export glowDebugCallback_glcore44
|
|
||||||
func glowDebugCallback_glcore44(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message *uint8,
|
|
||||||
userParam unsafe.Pointer) {
|
|
||||||
if userDebugCallback != nil {
|
|
||||||
userDebugCallback(source, gltype, id, severity, length, GoStr(message), userParam)
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,71 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
// This file implements GlowGetProcAddress for every supported platform. The
|
|
||||||
// correct version is chosen automatically based on build tags:
|
|
||||||
//
|
|
||||||
// windows: WGL
|
|
||||||
// darwin: CGL
|
|
||||||
// linux freebsd: GLX
|
|
||||||
//
|
|
||||||
// Use of EGL instead of the platform's default (listed above) is made possible
|
|
||||||
// via the "egl" build tag.
|
|
||||||
//
|
|
||||||
// It is also possible to install your own function outside this package for
|
|
||||||
// retrieving OpenGL function pointers, to do this see InitWithProcAddrFunc.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
/*
|
|
||||||
#cgo windows CFLAGS: -DTAG_WINDOWS
|
|
||||||
#cgo windows LDFLAGS: -lopengl32
|
|
||||||
#cgo darwin CFLAGS: -DTAG_DARWIN
|
|
||||||
#cgo darwin LDFLAGS: -framework OpenGL
|
|
||||||
#cgo linux freebsd CFLAGS: -DTAG_POSIX
|
|
||||||
#cgo linux freebsd LDFLAGS: -lGL
|
|
||||||
#cgo egl CFLAGS: -DTAG_EGL
|
|
||||||
#cgo egl LDFLAGS: -lEGL
|
|
||||||
// Check the EGL tag first as it takes priority over the platform's default
|
|
||||||
// configuration of WGL/GLX/CGL.
|
|
||||||
#if defined(TAG_EGL)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <EGL/egl.h>
|
|
||||||
void* GlowGetProcAddress_glcore44(const char* name) {
|
|
||||||
return eglGetProcAddress(name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_WINDOWS)
|
|
||||||
#define WIN32_LEAN_AND_MEAN 1
|
|
||||||
#include <windows.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
static HMODULE ogl32dll = NULL;
|
|
||||||
void* GlowGetProcAddress_glcore44(const char* name) {
|
|
||||||
void* pf = wglGetProcAddress((LPCSTR) name);
|
|
||||||
if (pf) {
|
|
||||||
return pf;
|
|
||||||
}
|
|
||||||
if (ogl32dll == NULL) {
|
|
||||||
ogl32dll = LoadLibraryA("opengl32.dll");
|
|
||||||
}
|
|
||||||
return GetProcAddress(ogl32dll, (LPCSTR) name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_DARWIN)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <dlfcn.h>
|
|
||||||
void* GlowGetProcAddress_glcore44(const char* name) {
|
|
||||||
return dlsym(RTLD_DEFAULT, name);
|
|
||||||
}
|
|
||||||
#elif defined(TAG_POSIX)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <GL/glx.h>
|
|
||||||
void* GlowGetProcAddress_glcore44(const char* name) {
|
|
||||||
return glXGetProcAddress((const GLubyte *) name);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
func getProcAddress(namea string) unsafe.Pointer {
|
|
||||||
cname := C.CString(namea)
|
|
||||||
defer C.free(unsafe.Pointer(cname))
|
|
||||||
return C.GlowGetProcAddress_glcore44(cname)
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// #include <stdlib.h>
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
// Ptr takes a slice or pointer (to a singular scalar value or the first
|
|
||||||
// element of an array or slice) and returns its GL-compatible address.
|
|
||||||
//
|
|
||||||
// For example:
|
|
||||||
//
|
|
||||||
// var data []uint8
|
|
||||||
// ...
|
|
||||||
// gl.TexImage2D(gl.TEXTURE_2D, ..., gl.UNSIGNED_BYTE, gl.Ptr(&data[0]))
|
|
||||||
func Ptr(data interface{}) unsafe.Pointer {
|
|
||||||
if data == nil {
|
|
||||||
return unsafe.Pointer(nil)
|
|
||||||
}
|
|
||||||
var addr unsafe.Pointer
|
|
||||||
v := reflect.ValueOf(data)
|
|
||||||
switch v.Type().Kind() {
|
|
||||||
case reflect.Ptr:
|
|
||||||
e := v.Elem()
|
|
||||||
switch e.Kind() {
|
|
||||||
case
|
|
||||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
|
||||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
|
||||||
reflect.Float32, reflect.Float64:
|
|
||||||
addr = unsafe.Pointer(e.UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported pointer to type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", e.Kind()))
|
|
||||||
}
|
|
||||||
case reflect.Uintptr:
|
|
||||||
addr = unsafe.Pointer(v.Pointer())
|
|
||||||
case reflect.Slice:
|
|
||||||
addr = unsafe.Pointer(v.Index(0).UnsafeAddr())
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unsupported type %s; must be a slice or pointer to a singular scalar value or the first element of an array or slice", v.Type()))
|
|
||||||
}
|
|
||||||
return addr
|
|
||||||
}
|
|
||||||
|
|
||||||
// PtrOffset takes a pointer offset and returns a GL-compatible pointer.
|
|
||||||
// Useful for functions such as glVertexAttribPointer that take pointer
|
|
||||||
// parameters indicating an offset rather than an absolute memory address.
|
|
||||||
func PtrOffset(offset int) unsafe.Pointer {
|
|
||||||
return unsafe.Pointer(uintptr(offset))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Str takes a null-terminated Go string and returns its GL-compatible address.
|
|
||||||
// This function reaches into Go string storage in an unsafe way so the caller
|
|
||||||
// must ensure the string is not garbage collected.
|
|
||||||
func Str(str string) *uint8 {
|
|
||||||
if !strings.HasSuffix(str, "\x00") {
|
|
||||||
panic("str argument missing null terminator: " + str)
|
|
||||||
}
|
|
||||||
header := (*reflect.StringHeader)(unsafe.Pointer(&str))
|
|
||||||
return (*uint8)(unsafe.Pointer(header.Data))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GoStr takes a null-terminated string returned by OpenGL and constructs a
|
|
||||||
// corresponding Go string.
|
|
||||||
func GoStr(cstr *uint8) string {
|
|
||||||
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strs takes a list of Go strings (with or without null-termination) and
|
|
||||||
// returns their C counterpart.
|
|
||||||
//
|
|
||||||
// The returned free function must be called once you are done using the strings
|
|
||||||
// in order to free the memory.
|
|
||||||
//
|
|
||||||
// If no strings are provided as a parameter this function will panic.
|
|
||||||
func Strs(strs ...string) (cstrs **uint8, free func()) {
|
|
||||||
if len(strs) == 0 {
|
|
||||||
panic("Strs: expected at least 1 string")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate a contiguous array large enough to hold all the strings' contents.
|
|
||||||
n := 0
|
|
||||||
for i := range strs {
|
|
||||||
n += len(strs[i])
|
|
||||||
}
|
|
||||||
data := C.malloc(C.size_t(n))
|
|
||||||
|
|
||||||
// Copy all the strings into data.
|
|
||||||
dataSlice := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
|
|
||||||
Data: uintptr(data),
|
|
||||||
Len: n,
|
|
||||||
Cap: n,
|
|
||||||
}))
|
|
||||||
css := make([]*uint8, len(strs)) // Populated with pointers to each string.
|
|
||||||
offset := 0
|
|
||||||
for i := range strs {
|
|
||||||
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
|
|
||||||
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
|
|
||||||
offset += len(strs[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
return (**uint8)(&css[0]), func() { C.free(data) }
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
// Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT.
|
|
||||||
|
|
||||||
package gl
|
|
||||||
|
|
||||||
import "C"
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
type DebugProc func(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message string,
|
|
||||||
userParam unsafe.Pointer)
|
|
||||||
|
|
||||||
var userDebugCallback DebugProc
|
|
||||||
|
|
||||||
//export glowDebugCallback_glcompatibility45
|
|
||||||
func glowDebugCallback_glcompatibility45(
|
|
||||||
source uint32,
|
|
||||||
gltype uint32,
|
|
||||||
id uint32,
|
|
||||||
severity uint32,
|
|
||||||
length int32,
|
|
||||||
message *uint8,
|
|
||||||
userParam unsafe.Pointer) {
|
|
||||||
if userDebugCallback != nil {
|
|
||||||
userDebugCallback(source, gltype, id, severity, length, GoStr(message), userParam)
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue