-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support eval(lua scripts) command
- Loading branch information
1 parent
b7511c6
commit 0059c24
Showing
6 changed files
with
110 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/xgzlucario/rotom/internal/dict" | ||
lua "github.com/yuin/gopher-lua" | ||
) | ||
|
||
func luaCall(L *lua.LState) int { | ||
fn := L.ToString(1) | ||
keys := L.GetGlobal("KEYS").(*lua.LTable) | ||
switch fn { | ||
case "set": | ||
return luaSet(L, keys) | ||
case "get": | ||
return luaGet(L, keys) | ||
} | ||
return -1 | ||
} | ||
|
||
func luaSet(L *lua.LState, keys *lua.LTable) int { | ||
key := keys.RawGetInt(1).String() | ||
value := keys.RawGetInt(2).String() | ||
db.dict.Set(key, []byte(value)) | ||
L.Push(lua.LString("OK")) | ||
return 1 | ||
} | ||
|
||
func luaGet(L *lua.LState, keys *lua.LTable) int { | ||
key := keys.RawGetInt(1).String() | ||
value, ttl := db.dict.Get(key) | ||
if ttl != dict.KEY_NOT_EXIST { | ||
L.Push(lua.LString(value.([]byte))) | ||
} else { | ||
L.Push(lua.LNil) | ||
} | ||
return 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters