-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtools-methods.go
More file actions
48 lines (39 loc) · 1.7 KB
/
tools-methods.go
File metadata and controls
48 lines (39 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package luajit
import (
"reflect"
)
// MethodsAddFilter_tableIndex extends table _G[tableIndex] with all `o` methods :
// - condition : only consider functions having filter() returning non-empty string
// - exported name : use filter() result
func (L *State) MethodsAddFilter_tableIndex(tableIndex Index, oValue reflect.Value, filter fnFuncsAddFilter) {
for i := 0; i < oValue.NumMethod(); i++ {
var (
method_func = oValue.Method(i).Interface()
method_name = oValue.Type().Method(i).Name
)
if method_name = filter(method_name); method_name == "" {
continue
}
//fmt.Printf("MethodsAddFilter_tableIndex [ %d] : %s\n", i, method_name)
L.SetFieldAny(tableIndex, method_name, method_func)
}
}
// MethodsAddFilter_tableName extends table _G[tableName] with all `o` methods :
// - condition : only consider functions having filter() returning non-empty string
// - exported name : use filter() result
func (L *State) MethodsAddFilter_tableName(tableName string, o any, filter fnFuncsAddFilter) {
//fmt.Printf("MethodsAddFilter_tableName _G[%s] type %T\n", tableName, o)
L.TableGet(tableName)
defer L.Pop(1)
L.MethodsAddFilter_tableIndex(-1, reflect.ValueOf(o), filter)
}
// MethodsAdd_prefix extends table _G[tableName] with all `o` methods named `prefix`* :
// - exported name : will have "Lua_" prefix stripped
func (L *State) MethodsAdd_prefix(tableName string, o any, prefix string) {
L.MethodsAddFilter_tableName(tableName, o, FilterFuncsPrefix(prefix))
}
// MethodsAdd extends table _G[tableName] with all `o` methods named "Lua_*" :
// - exported name : will have "Lua_" prefix stripped
func (L *State) MethodsAdd(tableName string, o any) {
L.MethodsAdd_prefix(tableName, o, "Lua_")
}