Re: [go-nuts] Re: Pointer constraint to generics

2023-04-15 Thread Jan
Thanks for the suggestions Alex. Interesting that enumerating the pointers in a constraint would work ... but it makes sense. I think I disagree with the statement about not wanting to allow any pointer type. From my project perspective there will be indeed a limited number of those (~10).

Re: [go-nuts] Re: Pointer constraint to generics

2023-04-15 Thread 'Axel Wagner' via golang-nuts
I guess thinking about some more, I don't really understand the point of what you're doing. It seems you *can* actually get the static guarantee you want - you just have to spell the call `(*C.mystruct)(UnsafePointerOrError(s))` instead of `PointerOrError[C.mystruct](s)`. If you *could* restrict

Re: [go-nuts] Re: Pointer constraint to generics

2023-04-15 Thread 'Axel Wagner' via golang-nuts
You should be able to instantiate the function using a Pointer. That is, you can write func PointerOrError[T any](s C.StatusOr) (t T, err error) { var ptr unsafe.Pointer ptr, err = UnsafePointerOrError(s) // <-- unsafe.Pointer, error if err != nil { return

Re: [go-nuts] Importing a package declared in the root directory of a module

2023-04-15 Thread Victor Giordano
*Thanks again!* El sáb, 15 abr 2023 a las 16:50, 'Sean Liao' via golang-nuts (< golang-nuts@googlegroups.com>) escribió: > the import path specifies the location to find a package, but the actual > identifier used is the one in the package declaration, so > > import "a_module_path" > > var foo =

Re: [go-nuts] Importing a package declared in the root directory of a module

2023-04-15 Thread 'Sean Liao' via golang-nuts
the import path specifies the location to find a package, but the actual identifier used is the one in the package declaration, so import "a_module_path" var foo = util.Foo - sean On Sat, Apr 15, 2023, 20:40 Victor Giordano wrote: > Thanks *Sean!!* > That makes sense for me! > > But i guess

Re: [go-nuts] Importing a package declared in the root directory of a module

2023-04-15 Thread Victor Giordano
Thanks *Sean!!* That makes sense for me! But i guess I must import with an alias as import without an alias doesn't works, right? @:/cmd$ go build . # a_module_path/cmd ./main.go:4:2: imported and not used: "a_module_path" as util ./main.go:9:14: undefined: a_module_path main.go package main

Re: [go-nuts] Importing a package declared in the root directory of a module

2023-04-15 Thread 'Sean Liao' via golang-nuts
import "a_module_path" optionally rename it to make it clearer import util "a_module_path" - sean On Sat, Apr 15, 2023, 20:31 Victor Giordano wrote: > Hi there! > > I was playing a little bit with modules and packages, regarding making > projects. > And I'm struggling to use a package

[go-nuts] Importing a package declared in the root directory of a module

2023-04-15 Thread Victor Giordano
Hi there! I was playing a little bit with modules and packages, regarding making projects. And I'm struggling to use a package (non-main) declared in the root directory.. allow me to show an example: This scenario, I have project somewhere on my file system . ├── cmd │ └── main.go ├──

[go-nuts] Re: Pointer constraint to generics

2023-04-15 Thread Jan
Re-factoring your example to use CGO, in a small main.go file: ``` $ go run . ./main.go:28:10: cannot use incomplete (or unallocatable) type as a type argument: main._Ctype_struct_MyThing $ cat main.go package main // struct MyThing; // typedef struct MyThing MyThing; import "C" import (

[go-nuts] Re: Pointer constraint to generics

2023-04-15 Thread Jan
Thanks! I hadn't realized that one could constraint T to be a pointer type by using a second type paramater Q, this in nice. But alas, it doesn't work. When I copy your code to mine, and used an undefined C type ... it complained of the same thing: ``` cannot use incomplete (or unallocatable)

[go-nuts] Re: Pointer constraint to generics

2023-04-15 Thread jake...@gmail.com
What About: func PointerOrError[T *Q, Q any](s C.StatusOr ) (t T, err error) Seems to compile: https://go.dev/play/p/n4I-XkONj-O?v=gotip On Saturday, April 15, 2023 at 6:28:39 AM UTC-4 Jan wrote: > hi, > > This is a variation for a previous topic >

Re: [go-nuts] Avoid forcing my module users' to carry dependencies from code that live under the same repo just as examples/ debugging purposes.

2023-04-15 Thread Jim Idle
Indeed. Some parts of it are fine though, given that the ask was for a starting point. I agree completely with the pkg stuff being wrong. I use just some of the ideas here, but I don’t see what the point of pkg is. On Fri, Apr 14, 2023 at 16:04 'Dan Kortschak' via golang-nuts <

[go-nuts] Pointer constraint to generics

2023-04-15 Thread Jan
hi, This is a variation for a previous topic , but since there isn't a clear solution, I thought I would ask if anyone can think of a work around. I've been interacting a lot with C++ libraries from Go, and one of the

[go-nuts] Re: cgo Compiling C files housed in different directory than Go files

2023-04-15 Thread Jason E. Aten
and https://github.com/stevedonovan/luar On Saturday, April 15, 2023 at 9:13:03 AM UTC+1 Jason E. Aten wrote: > perhaps take a look at how the Go bindings for Lua work. > https://github.com/aarzilli/golua > > On Friday, April 14, 2023 at 6:14:05 PM UTC+1 Palash B wrote: > >> Hello folks. >> >>

[go-nuts] Re: cgo Compiling C files housed in different directory than Go files

2023-04-15 Thread Jason E. Aten
perhaps take a look at how the Go bindings for Lua work. https://github.com/aarzilli/golua On Friday, April 14, 2023 at 6:14:05 PM UTC+1 Palash B wrote: > Hello folks. > > I am working on writing an Interpreter (for my own programming language) > which is written in C and I want to build a Go