Generate lookup tables directly inside your source files from compact comment directives.
TableSmith keeps LUT generation close to the code that consumes it, and can replace an existing generated table in place when the expression changes.
Supported targets today are C, C++, Rust, JavaScript, TypeScript, and Python.
- Keep generated constant data checked into source control.
- Regenerate tables without switching to an external script or build step.
- Use one directive format across multiple languages.
- Fit embedded, DSP, graphics, parsing, and general precomputed-data workflows.
- Generate lookup tables from a compact inline directive.
- Regenerate existing tables without touching unrelated code.
- Use the active editor language to choose the output form.
- Support iterator controls such as
start,step, andend. - Evaluate expressions with a built-in safe math parser rather than arbitrary JavaScript execution.
Add a directive comment immediately above the table you want to generate, then run TableSmith: Regenerate LUTs from the command palette.
Common use cases:
- Sine, cosine, and waveform tables
- Gamma correction tables
- Quantization tables
- CRC or parser lookup tables
- Precomputed coefficient tables
Example in C or C++:
// @lut uint8_t sine[16]; round((sin((i / 15) * PI * 2) * 0.5 + 0.5) * 255)
uint8_t sine[16] = {
128, 176, 218, 245, 255, 245, 218, 176,
128, 79, 37, 10, 0, 10, 37, 79
};Example in Python:
# @lut gamma[8]; round(pow(i / 7, 2.2) * 255)
gamma = [
0, 5, 21, 50, 93, 151, 223, 255
]Supported forms:
// @lut TYPE NAME[SIZE]; EXPRESSION; CAST_TYPE; start=0, step=1, end=63
# @lut NAME[SIZE]; EXPRESSION; start=0, step=1, end=63
Rules:
@lutis optional, but recommended.TYPE NAME[SIZE]is used for typed targets such as C, C++, and Rust.NAME[SIZE]is used for untyped targets such as JavaScript and Python, and is also valid in TypeScript.CAST_TYPEis optional and supported for C, C++, and Rust outputs.start,step, andendare optional iterator controls.- When
endis present, the generated iterator must still produce exactlySIZEvalues.
Expressions can reference:
iindexsizestartstependPIEInfinityNaN
Supported functions include:
sin,cos,tanasin,acos,atanabs,round,floor,ceilmin,max,pow,sqrt,log,exp,clamp
Math.sin(...) style expressions are also accepted and normalized automatically.
c:TYPE name[SIZE] = { ... };cpp:static constexpr TYPE name[SIZE] = { ... };by defaultrust:const name: [TYPE; SIZE] = [ ... ];javascript:const name = [ ... ];typescript:const name: TYPE[] = [ ... ];when a type is presentpython:name = [ ... ]
If a generated table already exists directly under the directive, TableSmith replaces it. If no table exists yet, TableSmith inserts one.
tablesmith.cppDeclarationPrefix: Prefix applied to generated C++ LUTs. Default:static constexpr.
- Generated output style is chosen from the active editor language.
- The current C++ output uses raw arrays;
std::arrayis not yet implemented. - Expressions must evaluate to finite numbers.
- Source: github.com/srejv/table-smith
- Issues: github.com/srejv/table-smith/issues
npm install
npm test
npm run packagePress F5 in VS Code to launch an Extension Development Host.
Typical publish flow:
- Create or verify your Visual Studio Marketplace publisher.
- Authenticate
vscewith a personal access token. - Run
npm run packageto create a.vsix. - Run
npm run publishto publish the extension.