-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
493 additions
and
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package table_engine | ||
|
||
import ( | ||
"github.com/821869798/table-export/config" | ||
"github.com/821869798/table-export/field_type" | ||
"github.com/dop251/goja" | ||
"github.com/dop251/goja_nodejs/require" | ||
_ "github.com/dop251/goja_nodejs/util" | ||
) | ||
|
||
type TableEngine struct { | ||
runtime *goja.Runtime | ||
//util *goja.Object | ||
} | ||
|
||
func (c *TableEngine) NewTableFieldClass(name string) *field_type.TableFieldClass { | ||
return field_type.NewTableFieldClass(name) | ||
} | ||
|
||
func (c *TableEngine) NewTableFieldType(fieldType int) *field_type.TableFieldType { | ||
return field_type.NewTableFieldType(field_type.EFieldType(fieldType)) | ||
} | ||
|
||
func (c *TableEngine) NewTableFieldEnumType(name string) *field_type.TableFieldType { | ||
return field_type.NewTableFieldEnumType(name) | ||
} | ||
|
||
func (c *TableEngine) NewTableFieldArrayType(value *field_type.TableFieldType) *field_type.TableFieldType { | ||
return field_type.NewTableFieldArrayType(value) | ||
} | ||
|
||
func (c *TableEngine) NewTableFieldMapType(key *field_type.TableFieldType, value *field_type.TableFieldType) *field_type.TableFieldType { | ||
return field_type.NewTableFieldMapType(key, value) | ||
} | ||
|
||
func (c *TableEngine) NewTableFieldClassType(class *field_type.TableFieldClass) *field_type.TableFieldType { | ||
return field_type.NewTableFieldClassType(class) | ||
} | ||
|
||
//func (c *TableEngine) log(p func(string)) func(goja.FunctionCall) goja.Value { | ||
// return func(call goja.FunctionCall) goja.Value { | ||
// if format, ok := goja.AssertFunction(c.util.Get("format")); ok { | ||
// ret, err := format(c.util, call.Arguments...) | ||
// if err != nil { | ||
// panic(err) | ||
// } | ||
// | ||
// p(ret.String()) | ||
// } else { | ||
// panic(c.runtime.NewTypeError("util.format is not a function")) | ||
// } | ||
// | ||
// return nil | ||
// } | ||
//} | ||
|
||
func Require(runtime *goja.Runtime, module *goja.Object) { | ||
requireWithPrinter()(runtime, module) | ||
} | ||
|
||
func RequireWithPrinter() require.ModuleLoader { | ||
return requireWithPrinter() | ||
} | ||
|
||
func requireWithPrinter() require.ModuleLoader { | ||
return func(runtime *goja.Runtime, module *goja.Object) { | ||
c := &TableEngine{ | ||
runtime: runtime, | ||
} | ||
|
||
//c.util = require.Require(runtime, "util").(*goja.Object) | ||
|
||
o := module.Get("exports").(*goja.Object) | ||
o.Set("NewTableFieldClass", c.NewTableFieldClass) | ||
o.Set("NewTableFieldType", c.NewTableFieldType) | ||
o.Set("NewTableFieldEnumType", c.NewTableFieldEnumType) | ||
o.Set("NewTableFieldArrayType", c.NewTableFieldArrayType) | ||
o.Set("NewTableFieldMapType", c.NewTableFieldMapType) | ||
o.Set("NewTableFieldClassType", c.NewTableFieldClassType) | ||
o.Set("TableConfig", config.GlobalConfig.Table) | ||
} | ||
} | ||
|
||
func Enable(runtime *goja.Runtime) { | ||
runtime.Set("tableEngine", require.Require(runtime, "tableEngine")) | ||
} | ||
|
||
func init() { | ||
require.RegisterNativeModule("tableEngine", Require) | ||
} |
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,45 @@ | ||
package config | ||
|
||
type RawMetaRuleUnitCSBin struct { | ||
CodeTempDir string `toml:"code_temp_dir"` | ||
DataTempDir string `toml:"data_temp_dir"` | ||
GenCodeDir string `toml:"gen_code_dir"` | ||
DataBinDir string `toml:"data_bin_dir"` | ||
GenCodeNamespace string `toml:"code_namespace"` | ||
GenCodeHead string `toml:"gen_code_head"` | ||
CodeNotFoundKey string `toml:"code_not_found_key"` | ||
GenOptimizeData bool `toml:"gen_optimize"` | ||
EnumFiles []string `toml:"enum_files"` | ||
EnumDefinePrefix string `toml:"enum_define_prefix"` | ||
ClassDefinePrefix string `toml:"class_define_prefix"` | ||
BuiltinFieldTypes []string `toml:"builtin_field_types"` | ||
ScriptFieldTypes []string `toml:"script_field_types"` | ||
} | ||
|
||
func (r *RawMetaRuleUnitCSBin) RuleExportType() ExportType { | ||
return ExportType_CS_Bin | ||
} | ||
|
||
func (r *RawMetaRuleUnitCSBin) ActiveOptimizeData() bool { | ||
return r.GenOptimizeData | ||
} | ||
|
||
func (r *RawMetaRuleUnitCSBin) GetEnumFiles() []string { | ||
return r.EnumFiles | ||
} | ||
|
||
func (r *RawMetaRuleUnitCSBin) GetEnumDefinePrefix() string { | ||
return r.EnumDefinePrefix | ||
} | ||
|
||
func (r *RawMetaRuleUnitCSBin) GetClassDefinePrefix() string { | ||
return r.ClassDefinePrefix | ||
} | ||
|
||
func (r *RawMetaRuleUnitCSBin) GetBuiltinFieldTypes() []string { | ||
return r.BuiltinFieldTypes | ||
} | ||
|
||
func (r *RawMetaRuleUnitCSBin) GetExtFieldTypeScriptPath() []string { | ||
return r.ScriptFieldTypes | ||
} |
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
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
Oops, something went wrong.