コード例 #1
0
ファイル: instance.py.go プロジェクト: gemrs/gem
package world

import (
	"github.com/qur/gopy/lib"

	"github.com/gemrs/gem/pybind"
)

var WorldInstanceDef = pybind.Define("WorldInstance", (*Instance)(nil))
var RegisterWorldInstance = pybind.GenerateRegisterFunc(WorldInstanceDef)
var NewInstance = pybind.GenerateConstructor(WorldInstanceDef).(func() *Instance)

func (world *Instance) Py_sector(args *py.Tuple, kwds *py.Dict) (py.Object, error) {
	fn := pybind.Wrap(world.Sector)
	return fn(args, kwds)
}
コード例 #2
0
ファイル: coordinate.py.go プロジェクト: gemrs/gem
package position

import (
	"github.com/qur/gopy/lib"

	"github.com/gemrs/gem/pybind"
)

var AbsoluteDef = pybind.Define("Absolute", (*Absolute)(nil))
var RegisterAbsolute = pybind.GenerateRegisterFunc(AbsoluteDef)
var NewAbsolute = pybind.GenerateConstructor(AbsoluteDef).(func(int, int, int) *Absolute)

var SectorDef = pybind.Define("Sector", (*Sector)(nil))
var RegisterSector = pybind.GenerateRegisterFunc(SectorDef)
var NewSector = pybind.GenerateConstructor(SectorDef).(func(int, int, int) *Sector)

var RegionDef = pybind.Define("Region", (*Region)(nil))
var RegisterRegion = pybind.GenerateRegisterFunc(RegionDef)
var NewRegion = pybind.GenerateConstructor(RegionDef).(func(*Sector) *Region)

var LocalDef = pybind.Define("Local", (*Local)(nil))
var RegisterLocal = pybind.GenerateRegisterFunc(LocalDef)
var NewLocal = pybind.GenerateConstructor(LocalDef).(func(int, int, int, *Region) *Local)

var AreaDef = pybind.Define("Area", (*Area)(nil))
var RegisterArea = pybind.GenerateRegisterFunc(AreaDef)
var NewArea = pybind.GenerateConstructor(AreaDef).(func(*Sector, int, int) *Area)

func (pos *Absolute) PyGet_x() (py.Object, error) {
	fn := pybind.Wrap(pos.X)
	return fn(nil, nil)
コード例 #3
0
ファイル: profile.py.go プロジェクト: gemrs/gem
package player

import (
	"encoding/json"

	"github.com/qur/gopy/lib"

	"github.com/gemrs/gem/pybind"
)

var ProfileDef = pybind.Define("Profile", (*Profile)(nil))
var RegisterProfile = pybind.GenerateRegisterFunc(ProfileDef)
var NewProfile = pybind.GenerateConstructor(ProfileDef).(func(string, string) *Profile)

func (p *Profile) Py_serialize(args *py.Tuple, kwds *py.Dict) (py.Object, error) {
	fn := pybind.Wrap(func() string {
		obj, err := json.Marshal(p)
		if err != nil {
			panic(err)
		}
		return string(obj)
	})
	return fn(args, nil)
}

func (p *Profile) Py_deserialize(args *py.Tuple, kwds *py.Dict) (py.Object, error) {
	fn := pybind.Wrap(func(obj string) {
		err := p.UnmarshalJSON([]byte(obj))
		if err != nil {
			panic(err)
		}
コード例 #4
0
ファイル: player.py.go プロジェクト: gemrs/gem
package player

import (
	"github.com/qur/gopy/lib"

	"github.com/gemrs/gem/gem/game/server"
	"github.com/gemrs/gem/gem/game/world"
	"github.com/gemrs/gem/pybind"
)

var PlayerDef = pybind.Define("Player", (*Player)(nil))
var RegisterPlayer = pybind.GenerateRegisterFunc(PlayerDef)
var NewPlayer = pybind.GenerateConstructor(PlayerDef).(func(*server.Connection, *world.Instance) *Player)

func (client *Player) PyGet_username() (py.Object, error) {
	fn := pybind.Wrap(client.Profile().Username)
	return fn(nil, nil)
}

func (client *Player) Py_send_message(args *py.Tuple, kwds *py.Dict) (py.Object, error) {
	fn := pybind.Wrap(client.SendMessage)
	return fn(args, kwds)
}

func (client *Player) Py_warp(args *py.Tuple, kwds *py.Dict) (py.Object, error) {
	fn := pybind.Wrap(client.SetPosition)
	return fn(args, kwds)
}

func (client *Player) PyGet_skills() (py.Object, error) {
	fn := pybind.Wrap(client.Profile().Skills)
コード例 #5
0
ファイル: containers.py.go プロジェクト: gemrs/gem
package entity

import (
	"github.com/qur/gopy/lib"

	"github.com/gemrs/gem/pybind"
)

// These modules belong to gem.game.entity, registered in gem/game/entity/pymodule.go

var CollectionDef = pybind.Define("EntityCollection", (*Collection)(nil))
var RegisterCollection = pybind.GenerateRegisterFunc(CollectionDef)
var NewCollection = pybind.GenerateConstructor(CollectionDef).(func() *Collection)

func (c *Collection) Py_add(args *py.Tuple, kwds *py.Dict) (py.Object, error) {
	fn := pybind.Wrap(c.Add)
	return fn(args, kwds)
}

func (c *Collection) Py_remove(args *py.Tuple, kwds *py.Dict) (py.Object, error) {
	fn := pybind.Wrap(c.Remove)
	return fn(args, kwds)
}

func (c *Collection) Py_update(args *py.Tuple, kwds *py.Dict) (py.Object, error) {
	fn := pybind.Wrap(c.Update)
	return fn(args, kwds)
}

func (c *Collection) PyGet_adding() (py.Object, error) {
	fn := pybind.Wrap(c.Adding)
コード例 #6
0
ファイル: server.py.go プロジェクト: gemrs/gem
package archive

import (
	"github.com/qur/gopy/lib"

	"github.com/gemrs/gem/pybind"
)

var ServerDef = pybind.Define("Server", (*Server)(nil))
var RegisterServer = pybind.GenerateRegisterFunc(ServerDef)
var NewServer = pybind.GenerateConstructor(ServerDef).(func() *Server)

func (s *Server) Py_start(args *py.Tuple, kwds *py.Dict) (py.Object, error) {
	fn := pybind.Wrap(s.Start)
	return fn(args, kwds)
}

func (s *Server) Py_stop(args *py.Tuple, kwds *py.Dict) (py.Object, error) {
	fn := pybind.Wrap(s.Stop)
	return fn(args, kwds)
}
コード例 #7
0
ファイル: pybind_test.go プロジェクト: gemrs/gem
func (c *Cat) Init(name string) {
	fmt.Println("calling init")
	c.Name = name
	c.Cheeseburgers = 0
}

func (c *Cat) Rename(name string) {
	fmt.Println("calling rename")
	c.Name = name
}

func (c *Cat) GiveCheeseburger() {
	fmt.Println("calling burgers")
	c.Cheeseburgers++
}

func (c *Cat) Py_rename(args *py.Tuple, kwds *py.Dict) (py.Object, error) {
	fn := pybind.Wrap(c.Rename)
	return fn(args, kwds)
}

func (c *Cat) Py_give_cheeseburger(args *py.Tuple, kwds *py.Dict) (py.Object, error) {
	fn := pybind.Wrap(c.GiveCheeseburger)
	return fn(args, kwds)
}

var CatDef = pybind.Define("cat", (*Cat)(nil))
var RegisterCat = pybind.GenerateRegisterFunc(CatDef)
var NewCat = pybind.GenerateConstructor(CatDef).(func(string) *Cat)
コード例 #8
0
ファイル: py_listener.py.go プロジェクト: gemrs/gem
package event

import (
	"github.com/qur/gopy/lib"

	"github.com/gemrs/gem/pybind"
)

var PyListenerDef = pybind.Define("PyListener", (*PyListener)(nil))
var RegisterPyListener = pybind.GenerateRegisterFunc(PyListenerDef)
var NewPyListener = pybind.GenerateConstructor(PyListenerDef).(func(py.Object) *PyListener)

func (l *PyListener) PyGet_id() (py.Object, error) {
	fn := pybind.Wrap(l.Id)
	return fn(nil, nil)
}
コード例 #9
0
ファイル: appearance.py.go プロジェクト: gemrs/gem
package player

import (
	"github.com/gemrs/gem/pybind"
)

var AppearanceDef = pybind.Define("Appearance", (*Appearance)(nil))
var RegisterAppearance = pybind.GenerateRegisterFunc(AppearanceDef)
var NewAppearance = pybind.GenerateConstructor(AppearanceDef).(func() *Appearance)
コード例 #10
0
ファイル: update_service.py.go プロジェクト: gemrs/gem
package game

import (
	"github.com/gemrs/gem/gem/runite"
	"github.com/gemrs/gem/pybind"
)

var UpdateServiceDef = pybind.Define("UpdateService", (*UpdateService)(nil))
var RegisterUpdateService = pybind.GenerateRegisterFunc(UpdateServiceDef)
var NewUpdateService = pybind.GenerateConstructor(UpdateServiceDef).(func(*runite.Context) *UpdateService)
コード例 #11
0
ファイル: event.py.go プロジェクト: gemrs/gem
package event

import (
	"github.com/qur/gopy/lib"

	"github.com/gemrs/gem/pybind"
)

var EventDef = pybind.Define("Event", (*Event)(nil))
var RegisterEvent = pybind.GenerateRegisterFunc(EventDef)
var NewEvent = pybind.GenerateConstructor(EventDef).(func(string) *Event)

func (e *Event) PyGet_key() (py.Object, error) {
	fn := pybind.Wrap(e.Key)
	return fn(nil, nil)
}

func (e *Event) Py_register(args *py.Tuple, kwds *py.Dict) (py.Object, error) {
	fn := pybind.Wrap(e.Register)
	return fn(args, kwds)
}

func (e *Event) Py_unregister(args *py.Tuple, kwds *py.Dict) (py.Object, error) {
	fn := pybind.Wrap(e.Unregister)
	return fn(args, kwds)
}

// Py_notify_observers is a manual python wrapper of notify_observers, because
// pybind doesn't support ellipsis args
func (e *Event) Py_notify_observers(argsTuple *py.Tuple) (py.Object, error) {
	lock := py.NewLock()
コード例 #12
0
ファイル: sector.py.go プロジェクト: gemrs/gem
package world

import (
	"github.com/gemrs/gem/gem/game/position"
	"github.com/gemrs/gem/pybind"
)

var SectorDef = pybind.Define("Sector", (*Sector)(nil))
var RegisterSector = pybind.GenerateRegisterFunc(SectorDef)
var NewSector = pybind.GenerateConstructor(SectorDef).(func(*position.Sector) *Sector)
コード例 #13
0
ファイル: context.py.go プロジェクト: gemrs/gem
package log

import (
	"fmt"

	"github.com/qur/gopy/lib"

	"github.com/gemrs/gem/pybind"
)

var PyContextDef = pybind.Define("LogContext", (*PyContext)(nil))
var RegisterPyContext = pybind.GenerateRegisterFunc(PyContextDef)
var NewPyContext = pybind.GenerateConstructor(PyContextDef).(func() *PyContext)

type PyContext struct {
	py.BaseObject
}

func (ctx *PyContext) Init() {}

func (ctx *PyContext) ContextMap() map[string]interface{} {
	lock := py.NewLock()
	defer lock.Unlock()

	obj, err := ctx.CallMethod("log_context", "()")
	if err != nil {
		panic(fmt.Sprintf("cannot call log_context: %v", err))
	}

	var ctxObject py.Object
コード例 #14
0
ファイル: mob.py.go プロジェクト: gemrs/gem
package entity

import (
	"github.com/qur/gopy/lib"

	"github.com/gemrs/gem/gem/game/interface/entity"
	"github.com/gemrs/gem/pybind"
)

var GenericMobDef = pybind.Define("GenericMob", (*GenericMob)(nil))
var RegisterGenericMob = pybind.GenerateRegisterFunc(GenericMobDef)
var NewGenericMob = pybind.GenerateConstructor(GenericMobDef).(func(entity.WaypointQueue) *GenericMob)

func (mob *GenericMob) PyGet_position() (py.Object, error) {
	fn := pybind.Wrap(mob.Position)
	return fn(nil, nil)
}
コード例 #15
0
ファイル: provider.py.go プロジェクト: gemrs/gem
package auth

import (
	"fmt"

	"github.com/qur/gopy/lib"

	"github.com/gemrs/gem/pybind"
)

var ProviderImplDef = pybind.Define("ProviderImpl", (*ProviderImpl)(nil))
var RegisterProviderImpl = pybind.GenerateRegisterFunc(ProviderImplDef)
var NewProviderImpl = pybind.GenerateConstructor(ProviderImplDef).(func() *ProviderImpl)

func createAuthConstants(module *py.Module) error {
	for c := AuthPending; c < AuthEnd; c++ {
		pyInt := py.NewInt(int(c))
		if err := module.AddObject(fmt.Sprintf("%v", c), pyInt); err != nil {
			panic(err)
		}
	}
	return nil
}
コード例 #16
0
ファイル: game_service.py.go プロジェクト: gemrs/gem
package game

import (
	"github.com/qur/gopy/lib"

	"github.com/gemrs/gem/gem/auth"
	"github.com/gemrs/gem/gem/runite"
	"github.com/gemrs/gem/pybind"
)

var GameServiceDef = pybind.Define("GameService", (*GameService)(nil))
var RegisterGameService = pybind.GenerateRegisterFunc(GameServiceDef)
var NewGameService = pybind.GenerateConstructor(GameServiceDef).(func(*runite.Context, string, auth.Provider) (*GameService, error))

func (svc *GameService) PyGet_world() (py.Object, error) {
	fn := pybind.Wrap(svc.World)
	return fn(nil, nil)
}
コード例 #17
0
ファイル: runite.py.go プロジェクト: gemrs/gem
package runite

import (
	"github.com/qur/gopy/lib"

	"github.com/gemrs/gem/pybind"
)

var ContextDef = pybind.Define("Context", (*Context)(nil))
var RegisterContext = pybind.GenerateRegisterFunc(ContextDef)
var NewContext = pybind.GenerateConstructor(ContextDef).(func() *Context)

func (c *Context) Py_unpack(args *py.Tuple, kwds *py.Dict) (py.Object, error) {
	fn := pybind.Wrap(c.Unpack)
	return fn(args, kwds)
}
コード例 #18
0
ファイル: engine.py.go プロジェクト: gemrs/gem
package gem

import (
	"github.com/qur/gopy/lib"

	"github.com/gemrs/gem/pybind"
)

var EngineDef = pybind.Define("Engine", (*Engine)(nil))
var RegisterEngine = pybind.GenerateRegisterFunc(EngineDef)
var NewEngine = pybind.GenerateConstructor(EngineDef).(func() *Engine)

func (e *Engine) Py_start(args *py.Tuple, kwds *py.Dict) (py.Object, error) {
	fn := pybind.Wrap(e.Start)
	return fn(args, kwds)
}

func (e *Engine) Py_join(args *py.Tuple, kwds *py.Dict) (py.Object, error) {
	fn := pybind.Wrap(e.Join)
	return fn(args, kwds)
}

func (e *Engine) Py_stop(args *py.Tuple, kwds *py.Dict) (py.Object, error) {
	fn := pybind.Wrap(e.Stop)
	return fn(args, kwds)
}
コード例 #19
0
ファイル: connection.py.go プロジェクト: gemrs/gem
package server

import (
	"net"

	"github.com/qur/gopy/lib"

	"github.com/gemrs/gem/pybind"
	"github.com/gemrs/willow/log"
)

var ConnectionDef = pybind.Define("Connection", (*Connection)(nil))
var RegisterConnection = pybind.GenerateRegisterFunc(ConnectionDef)
var NewConnection = pybind.GenerateConstructor(ConnectionDef).(func(net.Conn, log.Log) *Connection)

func (c *Connection) PyGet_log() (py.Object, error) {
	fn := pybind.Wrap(c.Log)
	return fn(nil, nil)
}

func (c *Connection) Py_disconnect(args *py.Tuple, kwds *py.Dict) (py.Object, error) {
	fn := pybind.Wrap(c.Disconnect)
	return fn(args, kwds)
}
コード例 #20
0
ファイル: module.py.go プロジェクト: gemrs/gem
package log

import (
	"github.com/qur/gopy/lib"

	"github.com/gemrs/gem/pybind"
	"github.com/gemrs/willow/log"
)

var PyModuleDef = pybind.Define("Module", (*PyModule)(nil))
var RegisterPyModule = pybind.GenerateRegisterFunc(PyModuleDef)
var NewPyModule = pybind.GenerateConstructor(PyModuleDef).(func(string, py.Object) *PyModule)

type PyModule struct {
	py.BaseObject

	*log.Module
}

func (m *PyModule) Init(tag string, ctxObj py.Object) {
	var ctx log.Context
	if c, ok := ctxObj.(*PyContext); ok {
		ctx = c
	} else {
		ctx = log.NilContext
	}
	m.Module = log.New(tag, ctx).(*log.Module)
}

func (m *PyModule) PyGet_tag() (py.Object, error) {
	fn := pybind.Wrap(m.Module.Tag)