Skip to main content
Version: Next

Load at runtime

This page covers: reading config with generated code. The recommended shape is one Tables object.

Unity + JSON (most common)

  1. In Unity Package Manager, install the Runtime package com.code-philosophy.luban (Add package from git URL):
    • GitHub: https://github.com/focus-creative-games/luban_unity.git
    • Gitee: https://gitee.com/focus-creative-games/luban_unity.git
  2. Generate matching code/data (for Unity development, cs-simple-json + json is common). Place a script next to your config project like the following (adjust paths for your repo):
gen_client_json.bat
set WORKSPACE=..\..
set LUBAN_DLL=%WORKSPACE%\Tools\Luban\Luban.dll
set CONF_ROOT=%WORKSPACE%\DataTables

dotnet %LUBAN_DLL% ^
--conf %CONF_ROOT%\luban.conf ^
-t client ^
-c cs-simple-json ^
-d json ^
-x outputCodeDir=Assets/Gen ^
-x outputDataDir=Assets/StreamingAssets/json

A complete runnable example: luban_examples/Projects/Csharp_Unity_json/gen.bat.

  1. Load:
var tables = new cfg.Tables(file =>
JSON.Parse(File.ReadAllText($"{jsonDir}/{file}.json")));

var reward = tables.TbReward.Get(1001);
Debug.Log(reward.Name);

cfg / Tables / table names follow your luban.conf topModule, manager, and table definitions.

Key points

PointNotes
Entrynew Tables(loader)—not a global static per table
loaderGiven a file name, return that table’s JSON (or bin ByteBuf)
Accesstables.TbXxx.Get(key) or indexer (depends on generated code)
NamingExcel field item_id often becomes ItemId in C# (adjustable via codeStyle)

Other language samples: luban_examples/Projects. For non-Unity, copy the matching Runtime from the examples.

Dev JSON / release binary

The same loading code can distinguish JSON vs bin by what the loader returns (generation targets must match, e.g. cs-bin + bin). Details: Runtime loading.

Common pitfalls

  • codeTarget and dataTarget mismatch (e.g. code reads bin but data is json).
  • On Android and similar platforms, reading StreamingAssets paths directly may fail—read into memory first, then hand to the loader.
  • Default generated code tends to be synchronous; async needs template changes or your own wrapper.