-
Notifications
You must be signed in to change notification settings - Fork 689
Closed
Description
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
Labels
No labels