### Luban Lua Data Format Examples Source: https://luban.doc.code-philosophy.com/docs/beginner/manual/excelcompactformat Examples demonstrating the Lua table data format for representing data structures in Luban. This format uses key-value pairs, aligning with Lua's native table syntax. ```Lua {x=1.0, y=2.0, z=3.0} ``` ```Lua {id=1, name="xxxx", pos={"x":1, "y":2, "z":3}} ``` -------------------------------- ### Lua Data Source Example for Luban Source: https://luban.doc.code-philosophy.com/docs/beginner/1.x/manual/datasource This Lua snippet demonstrates a data record structure for Luban, showing how Lua tables are used for various data types. It highlights the return keyword, set format {v1, v2, ...}, map format {[key1] = value1, ...} with arbitrary key types, and the _type_ property for polymorphic beans. ```Lua return { x1 = false, x2 = 2, x3 = 128, x4 = 1122, x5 = 112233445566, x6 = 1.3, x7 = 1122, x10 = "yf", t1 = {key="/key/ab1", text="apple"}, x12 = {x1=1}, x13 = "D", x14 = { _type_="DemoD2", x1 = 1, x2=3}, v2 = {x= 1,y = 2}, v3 = {x=0.1, y= 0.2,z=0.3}, v4 = {x=1,y=2,z=3.5,w=4}, t1 = "1970-01-01 00:00:00", k1 = {1,2}, k2 = {2,3}, k8 = {[2]=10,[3]=12}, k9 = { {y1=1,y2=true}, {y1=10,y2=false} }, k15 = { { _type_="DemoD2", x1 = 1, x2=3} }, } ``` -------------------------------- ### Luban JSON Data Format Examples Source: https://luban.doc.code-philosophy.com/docs/beginner/manual/excelcompactformat Examples demonstrating the standard JSON data format for representing data structures in Luban. This format uses explicit field names, providing clarity and broad compatibility. ```JSON {"x":1.0, "y":2.0, "z":3.0} ``` ```JSON {"id":1, "name":"xxxx", "pos":{"x":1, "y":2, "z":3}} ``` -------------------------------- ### Luban Custom Table Importer Configuration Parameters Source: https://luban.doc.code-philosophy.com/docs/beginner/3.x/manual/importtable Lists and describes the configuration parameters available for customizing the automatic table import process in Luban, including their purpose, optionality, default values, and examples. ```APIDOC Configuration Parameters: - tableImporter.name: Required: No Description: TableImporter name. Default is 'default' for DefaultTableImporter. 'none' disables auto-import. Example: -x tableImporter.name=default - tableImporter.filePattern: Required: No Description: Automatic import file name rule (without suffix), in C# regular expression string format. Default is '#(.*)'. Example: -x tableImporter.filePattern=!(.*) - tableImporter.tableNamespaceFormat: Required: No Description: Format string for table namespace. Default is '{0}', which directly uses RawNamespace. Example: -x tableImporter.tableNamespaceFormat=My{0} - tableImporter.tableNameFormat: Required: No Description: Format string for table class name. Default is 'Tb{0}', which prefixes 'Tb' to RawName. Example: -x tableImporter.tableNameFormat=Cfg{0} - tableImporter.valueTypeNameFormat: Required: No Description: Format string for value_type class name. Default is '{0}', which uses RawName. If table namespace exists, it will be automatically prefixed. Example: -x tableImporter.valueTypeNameFormat=Va{0} ``` -------------------------------- ### XML Data Source Example for Luban Source: https://luban.doc.code-philosophy.com/docs/beginner/1.x/manual/datasource This XML snippet provides an example of a data record structure for Luban. It demonstrates how elements are used to represent various data types, including nested structures, and attributes like type for polymorphic beans. Arrays are represented by repeated elements. ```XML true 4 128 1 112233445566 1.3 1112232.43123 yf 1 C 1 2 1,2 1.2,2.3,3.4 1.2,2.2,3.2,4.3 1970-01-01 00:00:00 1 2 1 2 210 330 1 true 2 false 1 2 ``` -------------------------------- ### Luban Lite Data Format Examples Source: https://luban.doc.code-philosophy.com/docs/beginner/manual/excelcompactformat Examples demonstrating the compact, field-less 'lite' data format used in Luban for complex nested data structures. This format is designed for conciseness and efficient parsing, making it suitable for specific complex data scenarios. ```Data Structure {1.0, 2.0, 3.0} ``` ```Data Structure {1, xxxx, {1,2,3}} ``` -------------------------------- ### XML Configuration for Range Validator Source: https://luban.doc.code-philosophy.com/docs/beginner/manual/validator Demonstrates various examples of the 'range' validator, supporting fixed values, closed, open, and half-open/half-closed intervals for numeric types. Examples include fixed value (x0 must be 10), closed interval (x1 between [1,10]), open interval (x2 between (1,10]), half-open (x3 between [1,10)), and unbounded ranges (x5 [1,infinity], x6 [-infinity,100]). ```XML ``` -------------------------------- ### YAML Data Source Example for Luban Source: https://luban.doc.code-philosophy.com/docs/beginner/1.x/manual/datasource This YAML snippet demonstrates a data record structure for Luban, showcasing its concise syntax for various data types. It includes booleans, numbers, strings, nested objects, lists, and lists of key-value pairs. The $type property is used for polymorphic bean types. ```YAML x1: true x2: 3 x3: 128 x4: 40 x5: 11223344 x6: 1.2 x7: 1.23432 x10: hq x12: x1: 10 x13: B x14: $type: DemoD2 x1: 1 x2: 2 s1: key: "/key32" text: aabbcc22 v2: x: 1 y: 2 v3: x: 1.1 y: 2.2 z: 3.4 v4: x: 10.1 y: 11.2 z: 12.3 w: 13.4 t1: '1970-01-01 00:00:00' k1: - 1 - 2 k2: - 2 - 3 k8: - - 2 - 2 - - 4 - 10 k9: - y1: 1 y2: true - y1: 2 y2: false k15: - $type: DemoD2 x1: 1 x2: 2 ``` -------------------------------- ### Luban Table Definition: Singleton Mode Source: https://luban.doc.code-philosophy.com/docs/beginner/1.x/manual/define Defines a singleton table (`mode=singleton` or `mode=one`), which contains only a single record. This mode does not allow defining an `index` attribute. The example shows a table named `TbSingleton`. ```XML ``` -------------------------------- ### JSON Data Source Example for Luban Source: https://luban.doc.code-philosophy.com/docs/beginner/1.x/manual/datasource This JSON snippet illustrates a typical data record structure for Luban. It demonstrates various data types including booleans, integers, floats, strings, nested objects, arrays (sets), and arrays of key-value pairs (maps). It also shows the $type property for polymorphic bean types and the text type format. ```JSON { "x1":true, "x2":3, "x3":128, "x4":1, "x5":11223344, "x6":1.2, "x7":1.23432, "x10":"hq", "t1": {"key":"/key/xx1","text":"apple"}, "x12": { "x1":10}, "x13":"B", "x14":{"$type": "DemoD2", "x1":1, "x2":2}, "v2":{"x":1, "y":2}, "v3":{"x":1.1, "y":2.2, "z":3.4}, "v4":{"x":10.1, "y":11.2, "z":12.3, "w":13.4}, "t1":"1970-01-01 00:00:00", "k1":[1,2], "k2":[2,3], "k7":[2,3], "k8":[[2,2],[4,10]], "k9":[{"y1":1, "y2":true},{"y1":2, "y2":false}], "k15":[{"$type": "DemoD2", "x1":1, "x2":2}] } ``` -------------------------------- ### Luban Bean Type Definitions for Advanced Excel Examples Source: https://luban.doc.code-philosophy.com/docs/beginner/manual/exceladvanced This APIDOC snippet defines several Luban bean types (`Type1`, `Type2`, `Vec3`, `Type3`, `Type4`, `Title0`, `Title1`, `Title2`) that are used as foundational data structures in the advanced Excel format examples. These definitions showcase various data types, nested beans, vector types with custom separators, and structures designed for multi-level Excel headers, illustrating how complex data can be modeled for Luban's configuration system. ```APIDOC ``` -------------------------------- ### Luban Table Definition: List Mode (No Primary Key) Source: https://luban.doc.code-philosophy.com/docs/beginner/1.x/manual/define Defines a table in list mode with no primary key (`key个数为0`). This mode is suitable for simple lists without unique identifiers. The example shows a table named `TbNotKeyList`. ```XML
``` -------------------------------- ### Luban Table Definition: Map Mode Source: https://luban.doc.code-philosophy.com/docs/beginner/1.x/manual/define Defines a table with `mode=map`, which is the default key-value table. If `mode` and `index` are not specified, it defaults to map mode, using the first field of `value_type` as the key. The example shows a table named `TbNormalMap` with `key1` as the index. ```XML
``` -------------------------------- ### XML Configuration for Normal Path Validator Source: https://luban.doc.code-philosophy.com/docs/beginner/manual/validator Demonstrates the 'normal' path validator in XML bean definitions. It checks for resource existence based on a pattern where '*' is replaced by the field value. Requires 'pathValidator.rootDir' to be set. For example, it checks if the resource corresponding to the full path '${pathValidator.rootDir}/UI/${x}.text' exists, or for each element 'e' in 'x2', checks if '${pathValidator.rootDir}/Prefabs/${e}.prefab' exists. ```XML ``` -------------------------------- ### Define Range Validator for Numeric Fields in Configuration Schema Source: https://luban.doc.code-philosophy.com/docs/beginner/3.x/manual/validator This snippet demonstrates the 'range' validator, which supports fixed values or various interval notations (open, closed, half-open/closed) for numeric fields. It shows examples for integers with different range constraints, including unbounded ranges. ```Configuration Schema ``` -------------------------------- ### Luban Table Definition: List Mode (Union Multi-Key) Source: https://luban.doc.code-philosophy.com/docs/beginner/1.x/manual/define Defines a table in list mode with a composite primary key formed by multiple fields. Keys are combined using '+' to form a unique union primary key. The example shows `key1+key2+key3` as the index for `TbUnionMultiKey`. ```XML
``` -------------------------------- ### XML Configuration for Unity Path Validator Source: https://luban.doc.code-philosophy.com/docs/beginner/manual/validator Shows the 'unity' path validator. It directly checks if the '${pathValidator.rootDir}/{path}' file exists. A typical use case is working with Unity Engine's Addressables, by pointing 'pathValidator.rootDir' to the project's root directory. For example, it checks if the resource corresponding to the full path '${pathValidator.rootDir}/{x}' exists, or for each element 'e' in 'x2', checks if '${pathValidator.rootDir}/{e}' exists. ```XML ``` -------------------------------- ### XML Configuration for Index Validator Source: https://luban.doc.code-philosophy.com/docs/beginner/manual/validator For 'list,Bean' and 'array,Bean' types, the 'index' validator ensures uniqueness based on a specific field of the Bean within the list. For example, it requires the 'id' field within the 'foos' list to be unique. ```XML ``` -------------------------------- ### Luban Table Definition: List Mode (Independent Multi-Key) Source: https://luban.doc.code-philosophy.com/docs/beginner/1.x/manual/define Defines a table in list mode where multiple fields act as independent unique primary keys. Keys are separated by ',' indicating that each key is an independent unique index. The example shows `key1,key2,key3` as independent indices for `TbMultiKey`. ```XML
``` -------------------------------- ### XML Configuration for Size Validator Source: https://luban.doc.code-philosophy.com/docs/beginner/manual/validator The 'size' validator can only be applied to containers, used to check if the number of container elements meets the requirements. It must be defined as '(container_type#size=xx),element_type', not 'container_type,element_type#size=xxx', to avoid errors. It supports fixed size or range notation. For example, 'x' must have exactly 4 elements, and 'y' must have between 5 and 10 elements. ```XML ``` -------------------------------- ### Generate DotNet C# Binaries with Luban Source: https://luban.doc.code-philosophy.com/docs/beginner/manual/commandtools This batch script illustrates using Luban to generate C# code and binary data for a general .NET project. It sets up the environment variables for Luban, the configuration root, and defines output paths and localization settings via xargs parameters. ```batch set WORKSPACE=..\..\n\nset LUBAN_DLL=%WORKSPACE%\Tools\Luban\Luban.dll set CONF_ROOT=%WORKSPACE%\DataTables dotnet %LUBAN_DLL% ^ -t all ^ -c cs-bin ^ -d bin ^ --conf %CONF_ROOT%\luban.conf ^ -x outputCodeDir=Gen ^ -x outputDataDir=..\GenerateDatas\bytes ^ -x pathValidator.rootDir=%WORKSPACE%\Projects\Csharp_Unity_bin ^ -x l10n.textProviderFile=*@%WORKSPACE%\DataTables\Datas\l10n\texts.json ``` -------------------------------- ### Generate Unity C# Binaries with Luban Source: https://luban.doc.code-philosophy.com/docs/beginner/manual/commandtools This batch script demonstrates how to use Luban to generate C# code and binary data for a Unity project. It sets up the workspace, specifies the Luban DLL, configuration root, and uses xargs parameters to define output directories, path validation, and localization settings. ```batch set WORKSPACE=..\..\n\nset LUBAN_DLL=%WORKSPACE%\Tools\Luban\Luban.dll set CONF_ROOT=%WORKSPACE%\DataTables dotnet %LUBAN_DLL% ^ -t all ^ -c cs-bin ^ -d bin ^ --conf %CONF_ROOT%\luban.conf ^ -x outputCodeDir=Assets/Gen ^ -x outputDataDir=..\GenerateDatas\bytes ^ -x pathValidator.rootDir=%WORKSPACE%\Projects\Csharp_Unity_bin ^ -x l10n.textProviderFile=*@%WORKSPACE%\DataTables\Datas\l10n\texts.json ``` -------------------------------- ### Luban Supported Data Targets Source: https://luban.doc.code-philosophy.com/docs/beginner/3.x/manual/commandtools This section lists the various data export targets supported by Luban, including their descriptions and recommended use cases (e.g., compact binary, JSON, XML, YAML, Protobuf, Flatbuffers). It emphasizes the importance of matching data targets with code targets for successful data loading. ```APIDOC data target: bin description: Luban's unique binary format, compact, efficient, recommended for official release data target: bin-offset description: Records the index position of each record in the bin format exported data file, can be used for lazy loading at the record granularity data target: json description: JSON format, map output as [[key, value]] format data target: json2 description: Similar to json format, but map output as {"key":"value"} format data target: lua description: Lua format data target: xml description: XML format data target: yml description: YAML format data target: bson description: BSON format data target: msgpack description: MessagePack binary format data target: protobuf2-bin description: Protobuf2 binary format data target: protobuf3-bin description: Protobuf3 binary format data target: protobuf2-json description: Protobuf2 supported JSON format data target: protobuf3-json description: Protobuf3 supported JSON format data target: flatbuffers-json description: Flatbuffers supported JSON format data target: text-list description: Outputs all text keys that appear in the configuration, sorted from smallest to largest ``` -------------------------------- ### Load Luban Configurations in Unity with C# (Auto-Detect JSON/BIN) Source: https://luban.doc.code-philosophy.com/docs/beginner/manual/loadconfigatruntime This advanced C# code snippet for Unity projects allows automatic detection and loading of Luban configurations from either JSON or binary (BIN) formats without code changes. It uses reflection to determine the loader type based on the cfg.Tables constructor, optimizing for development (JSON) and production (BIN) environments. It includes helper functions for both JSON and ByteBuf loading. ```C# void Start() { var tablesCtor = typeof(cfg.Tables).GetConstructors()[0]; var loaderReturnType = tablesCtor.GetParameters()[0].ParameterType.GetGenericArguments()[1]; // 根据cfg.Tables的构造函数的Loader的返回值类型决定使用json还是ByteBuf Loader System.Delegate loader = loaderReturnType == typeof(ByteBuf) ? new System.Func(LoadByteBuf) : (System.Delegate)new System.Func(LoadJson); var tables = (cfg.Tables)tablesCtor.Invoke(new object[] {loader}); // 访问一个单例表 Console.WriteLine(tables.TbGlobal.Name); // 访问普通的 key-value 表 Console.WriteLine(tables.TbItem.Get(12).Name); // 支持 operator []用法 Console.WriteLine(tables.TbMail[1001].Desc); } private static JSONNode LoadJson(string file) { return JSON.Parse(File.ReadAllText($"{your_json_dir}/{file}.json", System.Text.Encoding.UTF8)); } private static ByteBuf LoadByteBuf(string file) { return new ByteBuf(File.ReadAllBytes($"{your_json_dir}/{file}.bytes")); } ``` -------------------------------- ### Load Luban Configurations in Unity with C# and JSON Source: https://luban.doc.code-philosophy.com/docs/beginner/manual/loadconfigatruntime This code snippet demonstrates how to load all Luban configurations in a Unity C# project when the data is exported in JSON format. It shows how to instantiate cfg.Tables and access singleton and key-value tables. It includes a helper function LoadJson to read JSON files. ```C# void Load() { // 一行代码可以加载所有配置。 cfg.Tables 包含所有表的一个实例字段。 var tables = new cfg.Tables(Loader); // 访问一个单例表 Console.WriteLine(tables.TbGlobal.Name); // 访问普通的 key-value 表 Console.WriteLine(tables.TbItem.Get(12).Name); // 支持 operator []用法 Console.WriteLine(tables.TbMail[1001].Desc); } private static JSONNode LoadJson(string file) { return JSON.Parse(File.ReadAllText($"{your_json_dir}/{file}.json", System.Text.Encoding.UTF8)); } ``` -------------------------------- ### Luban Supported Code Targets Source: https://luban.doc.code-philosophy.com/docs/beginner/3.x/manual/commandtools This section lists the various code generation targets supported by Luban, including their descriptions and recommended use cases for different programming languages and data formats (e.g., binary, JSON, Protobuf). It also notes compatibility requirements and output directory considerations for generating multiple targets. ```APIDOC code target: cs-bin description: C#, reads bin format files code target: cs-simple-json description: C#, uses SimpleJSON to read json files, recommended for Unity clients code target: cs-dotnet-json description: C#, uses System.Text.Json library to read json files, recommended for dotnet core servers code target: cs-newtonsoft-json description: C#, uses Newtonsoft.Json library to read json files code target: cs-editor-json description: C#, reads and saves records as a single json file, suitable for custom editors to save and load original configuration files code target: cs-protobuf2 description: Generates code to load all protobuf bin and json format data, only includes Tables class code target: cs-protobuf3 description: Generates code to load all protobuf bin and json format data, only includes Tables class code target: lua-lua description: Lua, reads lua format files code target: lua-bin description: Lua, reads bin format files code target: java-bin description: Java, reads bin format files code target: java-json description: Java, uses gson library to read json format files code target: cpp-bin description: C++, reads bin format files. Removed since v2.3.0 code target: cpp-sharedptr-bin description: C++, uses smart pointers to save dynamically allocated objects, reads bin format files code target: cpp-rawptr-bin description: C++, uses raw pointers to save dynamically allocated objects, reads bin format files code target: go-bin description: Go, reads bin format files code target: go-json description: Go, reads json format files code target: python-json description: Python, reads json format files code target: gdscript-json description: GDScript, reads json format files. Note: If you are developing with C#, it is recommended to use the more efficient cs-bin format code target: typescript-bin description: TypeScript, reads json format files code target: typescript-json description: TypeScript, reads json format files code target: typescript-protobuf description: TypeScript, generates code to read protobuf format data, only includes Tables class code target: rust-bin description: Generates Rust code, reads bin format files code target: rust-json description: Generates Rust code, reads json format files code target: php-json description: PHP, reads json format files code target: dart-json description: Generates Dart code, reads json format files code target: protobuf2 description: Generates proto2 syntax schema files code target: protobuf3 description: Generates proto3 syntax schema files code target: flatbuffers description: Generates flatbuffers schema files ``` -------------------------------- ### Luban Client: Generate Code and Data (Bin Format) with Test Data Source: https://luban.doc.code-philosophy.com/docs/beginner/1.x/manual/commandtools This command generates client-side code and data using the binary format for a Unity project. It includes test data and targets the 'client' service group. The output code goes to `d:\client\Assets\Gen` and data to `d:\client\Assets\StreamingAssets\GameData`. ```Shell dotnet d:\tools\Luban.Client\Luban.Client.dll ^ -h 127.0.0.1 ^ -p 8899 ^ -j cfg ^ -- ^ --define_file d:\raw_config\defines\__root__.xml ^ --input_data_dir d:\raw_configs\datas ^ --output_code_dir d:\client\Assets\Gen ^ --output_data_dir d:\client\Assets\StreamingAssets\GameData ^ --gen_types code_cs_unity_bin,data_bin ^ --service client ``` -------------------------------- ### Luban Supported Data Targets Source: https://luban.doc.code-philosophy.com/docs/beginner/manual/commandtools This section lists the various data formats that Luban can export configuration files into. These formats are designed to be compact, efficient, or compatible with specific serialization libraries, and are recommended for different deployment scenarios. ```APIDOC bin: Luban's unique binary format, compact, efficient, recommended for official release bin-offset: Records the index position of each record in the bin-exported data file, can be used for record-level lazy loading json: json format, map output as [[key, value]] format json2: Similar to json format, but map output as {"key":"value"} format lua: lua format xml: xml format yml: yaml format bson: bson format msgpack: msgpack binary format protobuf2-bin: protobuf2 binary format protobuf3-bin: protobuf3 binary format protobuf2-json: protobuf2 supported json format protobuf3-json: protobuf3 supported json format flatbuffers-json: flatbuffers supported json format text-list: Outputs all text keys that appear in the configuration, sorted from smallest to largest ``` -------------------------------- ### Luban Default Pipeline Source: https://luban.doc.code-philosophy.com/docs/beginner/manual/commandtools This section briefly describes the default pipeline implementation within Luban.Core, named 'default', and notes that users have the flexibility to implement their own custom pipelines. ```APIDOC Luban.Core implements a default pipeline named 'default'. Users can implement their own Pipelines. ``` -------------------------------- ### Luban xargs Command-line Parameters Source: https://luban.doc.code-philosophy.com/docs/beginner/manual/commandtools Detailed list of customizable parameters for the Luban tool, accessible via the `-x --xargs` command. These parameters allow fine-grained control over output directories, code styling, naming conventions, data exporters, post-processors, output savers, localization, path validation, line endings, and file encoding. ```APIDOC Parameters for Luban's -x --xargs option: - {codeTarget}.outputCodeDir: Code target output directory. Example: -x outputCodeDir=/my/output/dir - {dataTarget}.outputDataDir: Data target output directory. Example: -x outputDataDir=/my/output/dir - codeStyle: Code target naming style. Values: none, csharp-default, java-default, go-default, lua-default, typescript-default, cpp-default, python-default, dart-default. Example: -x codeStyle=csharp-default - namingConvention.{codeTarget}.{location}: Naming convention for specific code targets and locations (namespace, type, method, property, field, enumItem). Values: none, pascal, camel, upper, snake. Example: -x namingConvention.cs-bin.field=pascal - dataExporter: Data exporter. Values: null, default. Example: -x dataExporter=default - codePostprocess: Code post-processor (multiple allowed). Example: -x codePostProcess=a,b,c - dataPostprocess: Data post-processor (multiple allowed). Example: -x dataPostProcess=a,b - outputSaver: Data saver. Values: null, local. Default: local. Example: -x outputSaver=local - outputSaver.{codeTarget|dataTarget}.cleanUpOutputDir: Whether to clean output directory before saving. Default: true. Example: -x outputSaver.cs-bin.cleanUpOutputDir=0 - l10n.provider: Localization text provider. Value: default. Example: -x l10n.provider=default - l10n.textFile.path: Localization text data file path (required if l10n.provider is set). Example: -x l10n.textFile.path=xxxx - l10n.textFile.keyFieldName: Field name for text item key in localization file. Example: -x l10n.textFile.keyFieldName=key - l10n.textFile.languageFieldName: Field name for language-specific text value in localization file. Example: -x l10n.languageFieldName=en - l10n.convertTextKeyToValue: Perform static localization (replace key with text value). Example: -x l10n.convertTextKeyToValue=1 - l10n.textListFile: File for list of all text keys. - pathValidator.rootDir: Root directory for path validator to search files. Example: -x pathValidator.rootDir=/xx/yy - {code|data}.lineEnding: Line ending for generated text files. Values: CR, LF, CRLF. Default: Environment.NewLine. Example: -x lineEnding=LF, -x code.LineEnding=LF, -x data.lineEnding=LF - json.compact: Output compact JSON data (no indentation). Values: 0, 1, true, false. Default: 0. Example: -x compact=1 - {dataTarget}.fileExt: Output data file extension. Example: -x bin.fileExt=bin - ~~{dataTarget}.outputDataExtension~~: (Removed in v2.12.0, replaced by fileExt). Example: -x bin.outputDataExtension=bin - {codeTarget|dataTarget}.fileEncoding: Output file character encoding. Example: -x lua.fileEncoding=gb2313 ``` -------------------------------- ### Luban Supported Code Targets Source: https://luban.doc.code-philosophy.com/docs/beginner/manual/commandtools This section lists the various programming language and data format combinations supported by Luban for generating code to read configuration files. Each target specifies the language and the data format it can read, with some targets recommending specific libraries or use cases. ```APIDOC cs-bin: C#, reads bin format files cs-simple-json: C#, uses SimpleJSON to read json files, recommended for Unity client cs-dotnet-json: C#, uses System.Text.Json library to read json files, recommended for dotnet core server cs-newtonsoft-json: C#, uses Newtonsoft.Json library to read json files cs-editor-json: C#, reads and saves records as a single json file, suitable for custom editor saving and loading original configuration files cs-protobuf2: Generates code to load all protobuf bin and json format data, only includes Tables class cs-protobuf3: Generates code to load all protobuf bin and json format data, only includes Tables class lua-lua: lua, reads lua format files lua-bin: lua, reads bin format files java-bin: java, reads bin format files java-json: java, uses gson library to read json format files cpp-bin: cpp, reads bin format files. Removed since v2.3.0 cpp-sharedptr-bin: cpp, uses smart pointers to save dynamically allocated objects, reads bin format files cpp-rawptr-bin: cpp, uses raw pointers to save dynamically allocated objects, reads bin format files go-bin: go, reads bin format files go-json: go, reads json format files python-json: python, reads json format files gdscript-json: gdscript, reads json format files. Note: If you develop with C# language, it is recommended to use the more efficient cs-bin format typescript-bin: typescript, reads json format files typescript-json: typescript, reads json format files typescript-protobuf: typescript, generates code to read protobuf format data, only includes Tables class rust-bin: Generates rust code, reads bin format files rust-json: Generates rust code, reads json format files php-json: php, reads json format files dart-json: Generates dart code, reads json format files protobuf2: Generates proto2 syntax schema files protobuf3: Generates proto3 syntax schema files flatbuffers: Generates flatbuffers schema files ``` -------------------------------- ### Generate Unity C# JSON Data with Luban Source: https://luban.doc.code-philosophy.com/docs/beginner/manual/commandtools This batch script demonstrates how to use Luban to generate C# code and JSON data for a Unity project. It configures the Luban DLL, data tables, and specifies output directories for generated code and JSON files, along with path validation and localization settings. ```batch set WORKSPACE=..\..\n\nset GEN_CLIENT=%WORKSPACE%\Tools\Luban\Luban.dll set CONF_ROOT=%WORKSPACE%\DataTables dotnet %GEN_CLIENT% ^ -t all ^ -c cs-simple-json ^ -d json ^ --conf %CONF_ROOT%\luban.conf ^ -x outputCodeDir=Assets/Gen ^ -x outputDataDir=..\GenerateDatas\json ^ -x pathValidator.rootDir=D:\workspace2\luban_examples\Projects\Csharp_Unity_bin ^ -x l10n.textProviderFile=*@D:\workspace2\luban_examples\DataTables\Datas\l10n\texts.json ``` -------------------------------- ### Luban Tool: `gen_types` Parameter Options Source: https://luban.doc.code-philosophy.com/docs/beginner/1.x/manual/commandtools Detailed list of supported `gen_types` values for the Luban tool, categorized by code generation, data generation, and source data conversion. Each type specifies the target language/platform and data format. ```APIDOC Code Generation: - code_cs_bin: Generates .NET platform code for reading binary data. Uses System.Numerics.Vector{2,3,4}. - code_cs_unity_bin: Generates Unity-compatible code for reading binary data. Uses UnityEngine.Vector{2,3,4}. - code_cs_dotnet_json: Generates .NET platform code for reading JSON data. Uses System.Numerics.Vector{2,3,4}. - code_cs_unity_json: Generates Unity-compatible code for reading JSON data. Uses UnityEngine.Vector{2,3,4}. - code_cs_unity_editor_json: Generates code for Unity editor development. Supports loading/saving single records to JSON files. - code_lua_bin: Generates Lua code for reading binary data. - code_java_bin: Generates Java code for reading binary data. - code_java_json: Generates Java code for reading JSON data. - code_go_bin: Generates Go code for reading binary data. - code_go_json: Generates Go code for reading JSON data. - code_cpp_bin: Generates C++ code for reading binary data. - code_cpp_ue_editor_json: Generates code for UE4 editor development. Supports loading/saving single records to JSON files. - code_python27_json: Generates Python 2.7 code for reading JSON data. - code_python3_json: Generates Python 3 code for reading JSON data. - code_gdscript_json: Generates GDScript code for reading JSON data. - code_typescript_bin: Generates TypeScript code for reading binary data. - code_typescript_json: Generates TypeScript code for reading JSON data. - code_rust_json: Generates Rust code for reading JSON data. - code_protobuf2: Generates Protobuf 2 schema files. - code_protobuf3: Generates Protobuf 3 schema files. - code_template: Indicates use of custom code templates. - code_flatbuffers: Generates Flatbuffers schema files. Data Generation: - data_bin: Exports data in binary format. - data_bidx: Exports binary index data for record-level lazy loading. - data_lua: Exports data in Lua format. - data_json: Exports data in JSON format. - data_json_monolithic: Exports all table JSON data into a single JSON file (differs from data_json). - data_bson: Exports data in BSON format. - data_yaml: Exports data in YAML format. - data_xml: Exports data in XML format. - data_template: Custom data template. - data_protobuf_bin: Exports Protobuf binary data. - data_protobuf_json: Exports Protobuf 3 JSON data. - data_flatbuffers_json: Exports Flatbuffers JSON data. - data_resources: Exports all data tagged with 'res'. Source Data Conversion: - convert_json: Converts all source data to JSON source format (each record in a separate file). - convert_lua: Converts all source data to Lua source format (each record in a separate file). - convert_xlsx: Converts all source data to XLSX format (each table in a separate file). - convert_template: Custom conversion template (each record in a separate file). ``` -------------------------------- ### Luban Server: Generate Code and Data (JSON Format) with Test Data Source: https://luban.doc.code-philosophy.com/docs/beginner/1.x/manual/commandtools This command generates server-side code and data using the JSON format for a .NET C# project. It includes test data and targets the 'server' service group. The output code goes to `d:\server\src\Gen` and data to `d:\server\GameData`. ```Shell dotnet d:\tools\Luban.Client\Luban.Client.dll ^ -h 127.0.0.1 ^ -p 8899 ^ -j cfg ^ -- ^ --define_file d:\raw_config\defines\__root__.xml ^ --input_data_dir d:\raw_configs\datas ^ --output_code_dir d:\server\src\Gen ^ --output_data_dir d:\server\GameData ^ --gen_types code_cs_json,data_json ^ --service server ``` -------------------------------- ### Luban Client: Generate Code and Data (JSON Format) Excluding Dev/Test Tags Source: https://luban.doc.code-philosophy.com/docs/beginner/1.x/manual/commandtools This command generates client-side code and data using the JSON format for a Unity project. It excludes data tagged with 'dev' or 'test' and targets the 'client' service group. The output code goes to `d:\client\Assets\Gen` and data to `d:\client\Assets\StreamingAssets\GameData`. ```Shell dotnet d:\tools\Luban.Client\Luban.Client.dll ^ -h 127.0.0.1 ^ -p 8899 ^ -j cfg ^ -- ^ --define_file d:\raw_config\defines\__root__.xml ^ --input_data_dir d:\raw_configs\datas ^ --output_code_dir d:\client\Assets\Gen ^ --output_data_dir d:\client\Assets\StreamingAssets\GameData ^ --gen_types code_cs_unity_json,data_json ^ --service client ^ --export_exclude_tags dev,test ``` -------------------------------- ### Define Unreal Engine Path Validator in Configuration Schema Source: https://luban.doc.code-philosophy.com/docs/beginner/3.x/manual/validator This snippet demonstrates the 'ue' path validator, optimized for Unreal Engine's resource system. It checks for resources with the same name as the field, automatically appending '.uasset' or '.umap' and stripping prefixes like "blueprint'". 'pathValidator.rootDir' must point to the project's Content directory. ```Configuration Schema 检查 ${x} 对应的资源是否存在 检查x2的每个元素e ,${e} 对应的资源是否存在 ``` -------------------------------- ### Luban Default Table Importer Scan Rules Source: https://luban.doc.code-philosophy.com/docs/beginner/3.x/manual/importtable Explains the default file scanning and naming conventions for tables automatically imported by Luban's DefaultTableImporter. It details how file paths and names are transformed into table full names, value types, and namespaces. ```APIDOC DefaultTableImporter Scan Rules: - Scans all Excel family files (xls, xlsx, xlm, csv) starting with '#' in the luban.conf directory and its subdirectories. - Example: #Item.xlsx - full_name: TbItem - value_type: Item - mode: map - Example: reward/#Reward.xlsx - full_name: reward.TbReward - value_type: reward.Reward - mode: map - Example: item/equip/#Equip.csv - full_name: item.equip.TbEquip - value_type: item.equip.Equip - mode: map ``` -------------------------------- ### Luban Custom Table Importer Rule Definitions Source: https://luban.doc.code-philosophy.com/docs/beginner/3.x/manual/importtable Defines key variables used in customizing Luban's automatic table import rules, providing context for how file paths and names are parsed into components for formatting. ```APIDOC Variables for Custom Rules: - RawFullName: Description: Relative path of all directories converted to namespace (path separators '\\' or '/' replaced by '.') concatenated with the first group value from tableImporter.filePattern regex. Example: - filePattern=#(.*), filename #Item.xlsx -> Item - filename item/#Item.xlsx -> item.Item - RawNamespace: Description: Namespace part of RawFullName. Example: RawFullName item.Item -> item - RawName: Description: Class name part of RawFullName. Example: RawFullName item.Item -> Item ```