GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Do you need type conversion of struct? · Issue #220 · go-python/gpython

Do you need type conversion of struct? #220

New issue
Copy link
New issue
Copy link
Open
Open
Do you need type conversion of struct?#220
Copy link

Description

@wetor
wetor
opened on Mar 13, 2023
Issue body actions

When I use gpython as a plugin parser, I use reflect and recurrence to achieve a more general type conversion because of the trouble of type conversion.

Support mutual conversion of go type and gpython type including struct and map

Of course, the performance is not very good

https://github.com/wetor/AnimeGo/blob/feature-update_plugin/pkg/plugin/utils.go
and https://github.com/wetor/AnimeGo/blob/feature-update_plugin/pkg/utils/utils.go line 65, 76

Activity

  1. ncw commented on Mar 14, 2023

    @ncw
    ncw
    on Mar 14, 2023
    Collaborator
    More actions

    How do you think gpython should be helping here? Can you write an example? Thank you.

  2. wetor commented on Mar 14, 2023

    @wetor
    wetor
    on Mar 14, 2023
    ContributorAuthor
    More actions

    Based on my recent usage experience, I believe that gpython's embedded use lacks a convenient "bridge" for exchanging data with Go, such as the functionality in goja (https://github.com/dop251/goja) that exports types and methods from the VM as native Go types and functions. Currently, I do not have a specific plan for implementing this "bridge". However, I was wondering if you have any plans to develop gpython in the direction of an embedded script interpreter?

    Furthermore, I noticed this issue because I found basic type conversion code in py/util.go, and I thought I could improve it. I will provide examples later.

    Also, thank you for your contributions to this project. It's a great project.

  3. ncw commented on Mar 15, 2023

    @ncw
    ncw
    on Mar 15, 2023
    Collaborator
    More actions

    Based on my recent usage experience, I believe that gpython's embedded use lacks a convenient "bridge" for exchanging data with Go, such as the functionality in goja (https://github.com/dop251/goja) that exports types and methods from the VM as native Go types and functions.

    I see what you mean.

    Currently, I do not have a specific plan for implementing this "bridge". However, I was wondering if you have any plans to develop gpython in the direction of an embedded script interpreter?

    gpython is used like that so it seems like a good idea to make it easier for the user.

    Furthermore, I noticed this issue because I found basic type conversion code in py/util.go, and I thought I could improve it. I will provide examples later.

    Great. Yes that code could certainly be expanded.

    Also, thank you for your contributions to this project. It's a great project.

    :-)

  4. wetor commented on Mar 16, 2023

    @wetor
    wetor
    on Mar 16, 2023
    ContributorAuthor
    More actions

    example here https://go.dev/play/p/aT2zebez5zC?v=goprev

    Some uint types and pointer types are not supported. It's easy to add them, you know.
    Currently, all complex types are basically supported (there may be bugs)

    If you think it is useful, I will add some test cases and submit a push request

  5. ncw commented on Mar 16, 2023

    @ncw
    ncw
    on Mar 16, 2023
    Collaborator
    More actions

    Nice code!

    This converts Go structs into python dicts.

    Do you think converting them into a python object would be more pythonic? So

    Perhaps if we made a base class GoStruct or something like that it would make the process easier.

    So

    struct {
     X int
     Y string
    }
    

    Would become an instance of GoStruct with members X and Y as if it had been defined something like

    a = GoStruct()
    a.X = 1
    a.Y = "hello"

    Potentially this would allow python to call the methods on the struct too.

  6. wetor commented on Mar 18, 2023

    @wetor
    wetor
    on Mar 18, 2023
    ContributorAuthor
    More actions

    I also think it's better to convert to an object type. I just used it for data transfer, so I converted it to a dictionary. Perhaps we do need a similar 'GoStruct' type.

    Reacted by Nick Craig-Wood and sg3des
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.