<commit_before>package main

import (
	"fmt"
	"github.com/mattn/go-v8"
	"strconv"
)

const defaultPort = 9241

type identifier int32

func (i identifier) String() string {
	return strconv.Itoa(int(i))
}

const invalidIdentifier = identifier(-1)

type metaManager struct {
	players         *playerManager
	rooms           *roomManager
	items           *itemManager
	playerLocations *playerLocationManager
	itemLocations   *itemLocationManager
	script          *v8.V8Context
}

func initialize() *metaManager {
	initCommands()
	playerManager := newPlayerManager()
	roomManager := newRoomManager()
	itemManager := newItemManager()
	playerLocationManager := newPlayerLocationManager(roomManager, playerManager)
	itemLocationManager := newItemLocationManager(itemManager, roomManager, playerManager, playerLocationManager)
	roomManager.createRoom(room{
		id:          roomIdentifier(0),
		name:        "The Beginning",
		description: "Everything has a beginning. This is only one of many beginnings you will soon find as I continue typing in order to create a wall of text to test this. It's a very long sentence that precedes this slightly shorter one. Blarglblargl.",
		exits:       make(map[Direction]roomIdentifier),
	})

	world := &metaManager{
		players:         playerManager,
		rooms:           roomManager,
		items:           itemManager,
		playerLocations: playerLocationManager,
		itemLocations:   itemLocationManager,
		script:          nil,
	}
	//	initV8(world)
	world.script = initializeV8(world)
	return world
}

func debug() {
	v8ctx := v8.NewContext()
	//	v8ctx.Eval(`this.console = { "log" : function(args) { _console_log.apply(null, arguments) }}`)
	v8ctx.Eval("var fubar = 42")
	v8ctx.AddFunc("_console_log", func(args ...interface{}) interface{} {
		fmt.Printf("Go console log: ")
		for i := 0; i < len(args); i++ {
			fmt.Println()
			return ""
		}
		return ""
	})
	ret := v8ctx.MustEval(`
        var a = 1;
        var b = 'B'
        a += 2;
        a;
        `)
	fmt.Println("Eval result:", int(ret.(float64)))
	v8ctx.Eval(`console.log(a + 'fubar'+ b + 'baz' + 'something else`)
	v8ctx.Eval(`console.log('Hello World, 198570154')`)
	v8ctx.AddFunc("func_call", func(args ...interface{}) interface{} {
		f := func(args ...interface{}) interface{} {
			return "V8"
		}
		ret, _ = args[0].(v8.V8Function).Call("Go", 2, 1, f)
		return ret
	})
	fmt.Println(v8ctx.MustEval(`
        func_call(function() {
                return 'Hello ' + arguments[0];
        })
        `).(string))

	v8ctx.AddFunc("go_println", func(args ...interface{}) interface{} {
		if len(args) == 0 {
			return nil
		}
		var argString string
		var ok bool
		if argString, ok = args[0].(string); !ok {
			return nil
		}
		if len(argString) < 3 {
			return nil
		}
		argString = argString[1 : len(argString)-2]
		fmt.Println(argString)
		fmt.Println("wha?")
		return nil
	})
	v8ctx.Eval("go_println('Go Printline Works!')")

	toEval := "var a = 42;"
	selfId := identifier(42)
	wrappedToEval := "(function(self) {" + toEval + "})(" + selfId.String() + ")"
	v8ctx.Eval(wrappedToEval)
}

func main() {
	world := initialize()
	world.script.Eval("mud_println('World says, hello players');")
	world.script.Eval("window.setInterval(mud_println('Tick'), 100);")
	listen(*world)
}<commit_msg>added version to output<commit_after>package main

import (
	"fmt"
	"github.com/mattn/go-v8"
	"strconv"
)

const version = `0.0.0`
const defaultPort = 9241

type identifier int32

func (i identifier) String() string {
	return strconv.Itoa(int(i))
}

const invalidIdentifier = identifier(-1)

type metaManager struct {
	players         *playerManager
	rooms           *roomManager
	items           *itemManager
	playerLocations *playerLocationManager
	itemLocations   *itemLocationManager
	script          *v8.V8Context
}

func initialize() *metaManager {
	initCommands()
	playerManager := newPlayerManager()
	roomManager := newRoomManager()
	itemManager := newItemManager()
	playerLocationManager := newPlayerLocationManager(roomManager, playerManager)
	itemLocationManager := newItemLocationManager(itemManager, roomManager, playerManager, playerLocationManager)
	roomManager.createRoom(room{
		id:          roomIdentifier(0),
		name:        "The Beginning",
		description: "Everything has a beginning. This is only one of many beginnings you will soon find as I continue typing in order to create a wall of text to test this. It's a very long sentence that precedes this slightly shorter one. Blarglblargl.",
		exits:       make(map[Direction]roomIdentifier),
	})

	world := &metaManager{
		players:         playerManager,
		rooms:           roomManager,
		items:           itemManager,
		playerLocations: playerLocationManager,
		itemLocations:   itemLocationManager,
		script:          nil,
	}
	//	initV8(world)
	world.script = initializeV8(world)
	return world
}

func debug() {
	v8ctx := v8.NewContext()
	//	v8ctx.Eval(`this.console = { "log" : function(args) { _console_log.apply(null, arguments) }}`)
	v8ctx.Eval("var fubar = 42")
	v8ctx.AddFunc("_console_log", func(args ...interface{}) interface{} {
		fmt.Printf("Go console log: ")
		for i := 0; i < len(args); i++ {
			fmt.Println()
			return ""
		}
		return ""
	})
	ret := v8ctx.MustEval(`
        var a = 1;
        var b = 'B'
        a += 2;
        a;
        `)
	fmt.Println("Eval result:", int(ret.(float64)))
	v8ctx.Eval(`console.log(a + 'fubar'+ b + 'baz' + 'something else`)
	v8ctx.Eval(`console.log('Hello World, 198570154')`)
	v8ctx.AddFunc("func_call", func(args ...interface{}) interface{} {
		f := func(args ...interface{}) interface{} {
			return "V8"
		}
		ret, _ = args[0].(v8.V8Function).Call("Go", 2, 1, f)
		return ret
	})
	fmt.Println(v8ctx.MustEval(`
        func_call(function() {
                return 'Hello ' + arguments[0];
        })
        `).(string))

	v8ctx.AddFunc("go_println", func(args ...interface{}) interface{} {
		if len(args) == 0 {
			return nil
		}
		var argString string
		var ok bool
		if argString, ok = args[0].(string); !ok {
			return nil
		}
		if len(argString) < 3 {
			return nil
		}
		argString = argString[1 : len(argString)-2]
		fmt.Println(argString)
		fmt.Println("wha?")
		return nil
	})
	v8ctx.Eval("go_println('Go Printline Works!')")

	toEval := "var a = 42;"
	selfId := identifier(42)
	wrappedToEval := "(function(self) {" + toEval + "})(" + selfId.String() + ")"
	v8ctx.Eval(wrappedToEval)
}


func main() {
	world := initialize()
	world.script.Eval("mud_println('javascript engine functioning');")
//	world.script.Eval("window.setInterval(mud_println('Tick'), 100);")
	fmt.Println("version " + version)
	listen(*world)
}
{'fraction_non_alphanumeric': 0.14285714285714285, 'fraction_numerical': 0.01887647236484446, 'mean_word_length': 3.530095759233926, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2284184', 'n_tokens_mistral': 2360, 'n_tokens_neox': 2200, 'n_words': 523}