Skip to content

Used to support Chinese/Japanese or other #320

@TosakaWolf

Description

@TosakaWolf

lexer.go↓


//Character Set (128 - 255)
func isIdent(ch int, pos int) bool {
	return ch == '_' || 'A' <= ch && ch <= 'Z' || 'a' <= ch && ch <= 'z' || isDecimal(ch) && pos > 0 || 128 <= ch && ch <= 255
}

and
baselib.go↓

var baseFuncs = map[string]LGFunction{
	"輸出":             basePrint, //←Add this as needed
.....
}

then
Test it:

func TestIt(t *testing.T) {
	L := NewState()
	defer L.Close()
	meta := L.NewTable()

	L.SetGlobal("関数", meta)
	L.SetField(meta, "あ", L.NewFunction(newCounter))
	L.SetField(meta, "ア", L.NewFunction(incrCounter))
	L.SetField(meta, "ル", L.NewFunction(getCounter))
	err := L.DoString(`値 = 関数:あ(100)
		for 数=1,10 do
			輸出(値:ア(数))
		end
		輸出(値:ル())`)
	if err != nil {
		panic(err)
	}
}
func newCounter(L *LState) int {
	c := L.NewTable()
	self := L.CheckTable(1)
	value := LNumber(0)
	if L.GetTop() >= 2 {
		value = L.CheckNumber(2)
	}
	L.SetField(c, "value", value)
	L.SetMetatable(c, self)
	L.SetField(self, "__index", self)
	L.Push(c)
	return 1
}

func incrCounter(L *LState) int {
	self := L.CheckTable(1)
	value := LNumber(0)
	if L.GetTop() >= 2 {
		value = L.CheckNumber(2)
	}
	current := L.GetField(self, "value").(LNumber)
	current += value
	L.SetField(self, "value", current)
	L.Push(current)
	return 1
}

func getCounter(L *LState) int {
	self := L.CheckTable(1)
	value := L.GetField(self, "value").(LNumber)
	L.Push(value)
	return 1
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions