mirror of
https://github.com/litruv/picoGraph.git
synced 2026-07-24 10:46:06 +10:00
Initial commit
moved from private version control
This commit is contained in:
38
scripts/nodes/library/lua/coroutineCreate.js
Normal file
38
scripts/nodes/library/lua/coroutineCreate.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Creates a coroutine from a function using coroutine.create().
|
||||
*/
|
||||
export const luaCoroutineCreateNode = createNodeModule(
|
||||
{
|
||||
id: "lua_coroutine_create",
|
||||
title: "Coroutine Create",
|
||||
category: "Lua",
|
||||
description: "Wrap a function in a coroutine via coroutine.create().",
|
||||
searchTags: ["coroutine", "create", "lua"],
|
||||
inputs: [
|
||||
{
|
||||
id: "fn",
|
||||
name: "Function",
|
||||
direction: "input",
|
||||
kind: "any",
|
||||
description: "Function to run inside the coroutine",
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
id: "coroutine",
|
||||
name: "Coroutine",
|
||||
direction: "output",
|
||||
kind: "any",
|
||||
},
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const fn = resolveValueInput("fn", "function() end");
|
||||
return `coroutine.create(${fn})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
91
scripts/nodes/library/lua/coroutineResume.js
Normal file
91
scripts/nodes/library/lua/coroutineResume.js
Normal file
@@ -0,0 +1,91 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Resumes a coroutine and exposes the success flag and first result.
|
||||
*/
|
||||
export const luaCoroutineResumeNode = createNodeModule(
|
||||
{
|
||||
id: "lua_coroutine_resume",
|
||||
title: "Coroutine Resume",
|
||||
category: "Lua",
|
||||
description:
|
||||
"Resume a coroutine and capture the success flag alongside the first returned value.",
|
||||
searchTags: ["coroutine", "resume", "lua"],
|
||||
inputs: [
|
||||
{ id: "exec_in", name: "Exec", direction: "input", kind: "exec" },
|
||||
{
|
||||
id: "coroutine",
|
||||
name: "Coroutine",
|
||||
direction: "input",
|
||||
kind: "any",
|
||||
},
|
||||
{
|
||||
id: "arg1",
|
||||
name: "Arg 1",
|
||||
direction: "input",
|
||||
kind: "any",
|
||||
description: "Optional first value passed to coroutine",
|
||||
},
|
||||
{
|
||||
id: "arg2",
|
||||
name: "Arg 2",
|
||||
direction: "input",
|
||||
kind: "any",
|
||||
description: "Optional second value passed to coroutine",
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{ id: "exec_out", name: "Exec", direction: "output", kind: "exec" },
|
||||
{
|
||||
id: "success",
|
||||
name: "Success",
|
||||
direction: "output",
|
||||
kind: "boolean",
|
||||
},
|
||||
{
|
||||
id: "result",
|
||||
name: "Result",
|
||||
direction: "output",
|
||||
kind: "any",
|
||||
},
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
emitExec: ({
|
||||
node,
|
||||
indent,
|
||||
indentLevel,
|
||||
resolveValueInput,
|
||||
sanitizeIdentifier,
|
||||
emitNextExec,
|
||||
}) => {
|
||||
const OMIT = "__pg_omit__";
|
||||
const target = resolveValueInput("coroutine", "nil");
|
||||
const arg1 = resolveValueInput("arg1", OMIT);
|
||||
const arg2 = resolveValueInput("arg2", OMIT);
|
||||
const args = [target];
|
||||
if (arg1 !== OMIT) {
|
||||
args.push(arg1);
|
||||
}
|
||||
if (arg2 !== OMIT) {
|
||||
args.push(arg2);
|
||||
}
|
||||
const successName = sanitizeIdentifier(`__pg_${node.id}_co_success`);
|
||||
const resultName = sanitizeIdentifier(`__pg_${node.id}_co_result`);
|
||||
const line = `${indent(indentLevel)}local ${successName}, ${resultName} = coroutine.resume(${args.join(", ")})`;
|
||||
return [line, ...emitNextExec("exec_out")];
|
||||
},
|
||||
evaluateValue: ({ node, pinId, sanitizeIdentifier }) => {
|
||||
const successName = sanitizeIdentifier(`__pg_${node.id}_co_success`);
|
||||
const resultName = sanitizeIdentifier(`__pg_${node.id}_co_result`);
|
||||
if (pinId === "success") {
|
||||
return successName;
|
||||
}
|
||||
if (pinId === "result") {
|
||||
return resultName;
|
||||
}
|
||||
return "nil";
|
||||
},
|
||||
}
|
||||
);
|
||||
27
scripts/nodes/library/lua/coroutineRunning.js
Normal file
27
scripts/nodes/library/lua/coroutineRunning.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Returns the currently running coroutine via coroutine.running().
|
||||
*/
|
||||
export const luaCoroutineRunningNode = createNodeModule(
|
||||
{
|
||||
id: "lua_coroutine_running",
|
||||
title: "Coroutine Running",
|
||||
category: "Lua",
|
||||
description: "Access the currently running coroutine reference.",
|
||||
searchTags: ["coroutine", "running", "lua"],
|
||||
inputs: [],
|
||||
outputs: [
|
||||
{
|
||||
id: "coroutine",
|
||||
name: "Coroutine",
|
||||
direction: "output",
|
||||
kind: "any",
|
||||
},
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: () => "coroutine.running()",
|
||||
}
|
||||
);
|
||||
32
scripts/nodes/library/lua/coroutineStatus.js
Normal file
32
scripts/nodes/library/lua/coroutineStatus.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Reports a coroutine's status via coroutine.status().
|
||||
*/
|
||||
export const luaCoroutineStatusNode = createNodeModule(
|
||||
{
|
||||
id: "lua_coroutine_status",
|
||||
title: "Coroutine Status",
|
||||
category: "Lua",
|
||||
description: "Retrieve a coroutine's status string using coroutine.status().",
|
||||
searchTags: ["coroutine", "status", "lua"],
|
||||
inputs: [
|
||||
{
|
||||
id: "coroutine",
|
||||
name: "Coroutine",
|
||||
direction: "input",
|
||||
kind: "any",
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{ id: "status", name: "Status", direction: "output", kind: "string" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const target = resolveValueInput("coroutine", "nil");
|
||||
return `coroutine.status(${target})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
53
scripts/nodes/library/lua/coroutineYield.js
Normal file
53
scripts/nodes/library/lua/coroutineYield.js
Normal file
@@ -0,0 +1,53 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Yields from within a coroutine using coroutine.yield().
|
||||
*/
|
||||
export const luaCoroutineYieldNode = createNodeModule(
|
||||
{
|
||||
id: "lua_coroutine_yield",
|
||||
title: "Coroutine Yield",
|
||||
category: "Lua",
|
||||
description: "Yield execution from within a coroutine and optionally return values.",
|
||||
searchTags: ["coroutine", "yield", "lua"],
|
||||
inputs: [
|
||||
{ id: "exec_in", name: "Exec", direction: "input", kind: "exec" },
|
||||
{
|
||||
id: "value1",
|
||||
name: "Value 1",
|
||||
direction: "input",
|
||||
kind: "any",
|
||||
description: "Optional first value yielded to the caller",
|
||||
},
|
||||
{
|
||||
id: "value2",
|
||||
name: "Value 2",
|
||||
direction: "input",
|
||||
kind: "any",
|
||||
description: "Optional second value yielded to the caller",
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{ id: "exec_out", name: "Exec", direction: "output", kind: "exec" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
emitExec: ({ indent, indentLevel, resolveValueInput, emitNextExec }) => {
|
||||
const OMIT = "__pg_omit__";
|
||||
const value1 = resolveValueInput("value1", OMIT);
|
||||
const value2 = resolveValueInput("value2", OMIT);
|
||||
const args = [];
|
||||
if (value1 !== OMIT) {
|
||||
args.push(value1);
|
||||
}
|
||||
if (value2 !== OMIT) {
|
||||
args.push(value2);
|
||||
}
|
||||
const call = args.length
|
||||
? `${indent(indentLevel)}coroutine.yield(${args.join(", ")})`
|
||||
: `${indent(indentLevel)}coroutine.yield()`;
|
||||
return [call, ...emitNextExec("exec_out")];
|
||||
},
|
||||
}
|
||||
);
|
||||
27
scripts/nodes/library/lua/getMetatable.js
Normal file
27
scripts/nodes/library/lua/getMetatable.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Retrieves the metatable associated with a table via getmetatable().
|
||||
*/
|
||||
export const luaGetMetatableNode = createNodeModule(
|
||||
{
|
||||
id: "lua_getmetatable",
|
||||
title: "Get Metatable",
|
||||
category: "Lua",
|
||||
description: "Fetch a table's metatable using getmetatable().",
|
||||
searchTags: ["getmetatable", "metatable", "lua"],
|
||||
inputs: [
|
||||
{ id: "table", name: "Table", direction: "input", kind: "table" },
|
||||
],
|
||||
outputs: [
|
||||
{ id: "metatable", name: "Metatable", direction: "output", kind: "table" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const tableValue = resolveValueInput("table", "{}");
|
||||
return `getmetatable(${tableValue})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
63
scripts/nodes/library/lua/index.js
Normal file
63
scripts/nodes/library/lua/index.js
Normal file
@@ -0,0 +1,63 @@
|
||||
import { luaSetMetatableNode } from "./setMetatable.js";
|
||||
import { luaGetMetatableNode } from "./getMetatable.js";
|
||||
import { luaRawGetNode } from "./rawGet.js";
|
||||
import { luaRawSetNode } from "./rawSet.js";
|
||||
import { luaRawEqualNode } from "./rawEqual.js";
|
||||
import { luaCoroutineCreateNode } from "./coroutineCreate.js";
|
||||
import { luaCoroutineResumeNode } from "./coroutineResume.js";
|
||||
import { luaCoroutineYieldNode } from "./coroutineYield.js";
|
||||
import { luaCoroutineStatusNode } from "./coroutineStatus.js";
|
||||
import { luaCoroutineRunningNode } from "./coroutineRunning.js";
|
||||
|
||||
/**
|
||||
* Node modules covering Lua metatable and coroutine helpers.
|
||||
*/
|
||||
export const luaNodes = [
|
||||
luaSetMetatableNode,
|
||||
luaGetMetatableNode,
|
||||
luaRawGetNode,
|
||||
luaRawSetNode,
|
||||
luaRawEqualNode,
|
||||
luaCoroutineCreateNode,
|
||||
luaCoroutineResumeNode,
|
||||
luaCoroutineYieldNode,
|
||||
luaCoroutineStatusNode,
|
||||
luaCoroutineRunningNode,
|
||||
];
|
||||
|
||||
/**
|
||||
* Checklist tracking coverage of Lua metatable and coroutine helpers.
|
||||
* @type {Array<{ function: string, nodeId: string, implemented: boolean }>}
|
||||
*/
|
||||
export const luaFunctionChecklist = [
|
||||
{ function: "SETMETATABLE", nodeId: "lua_setmetatable", implemented: true },
|
||||
{ function: "GETMETATABLE", nodeId: "lua_getmetatable", implemented: true },
|
||||
{ function: "RAWGET", nodeId: "lua_rawget", implemented: true },
|
||||
{ function: "RAWSET", nodeId: "lua_rawset", implemented: true },
|
||||
{ function: "RAWEQUAL", nodeId: "lua_rawequal", implemented: true },
|
||||
{
|
||||
function: "COROUTINE.CREATE",
|
||||
nodeId: "lua_coroutine_create",
|
||||
implemented: true,
|
||||
},
|
||||
{
|
||||
function: "COROUTINE.RESUME",
|
||||
nodeId: "lua_coroutine_resume",
|
||||
implemented: true,
|
||||
},
|
||||
{
|
||||
function: "COROUTINE.YIELD",
|
||||
nodeId: "lua_coroutine_yield",
|
||||
implemented: true,
|
||||
},
|
||||
{
|
||||
function: "COROUTINE.STATUS",
|
||||
nodeId: "lua_coroutine_status",
|
||||
implemented: true,
|
||||
},
|
||||
{
|
||||
function: "COROUTINE.RUNNING",
|
||||
nodeId: "lua_coroutine_running",
|
||||
implemented: true,
|
||||
},
|
||||
];
|
||||
29
scripts/nodes/library/lua/rawEqual.js
Normal file
29
scripts/nodes/library/lua/rawEqual.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Compares two values using rawequal().
|
||||
*/
|
||||
export const luaRawEqualNode = createNodeModule(
|
||||
{
|
||||
id: "lua_rawequal",
|
||||
title: "Raw Equal",
|
||||
category: "Lua",
|
||||
description: "Compare values without metamethods using rawequal().",
|
||||
searchTags: ["rawequal", "compare", "lua"],
|
||||
inputs: [
|
||||
{ id: "a", name: "A", direction: "input", kind: "any" },
|
||||
{ id: "b", name: "B", direction: "input", kind: "any" },
|
||||
],
|
||||
outputs: [
|
||||
{ id: "equal", name: "Equal", direction: "output", kind: "boolean" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const a = resolveValueInput("a", "nil");
|
||||
const b = resolveValueInput("b", "nil");
|
||||
return `rawequal(${a}, ${b})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
29
scripts/nodes/library/lua/rawGet.js
Normal file
29
scripts/nodes/library/lua/rawGet.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Retrieves a raw table entry using rawget().
|
||||
*/
|
||||
export const luaRawGetNode = createNodeModule(
|
||||
{
|
||||
id: "lua_rawget",
|
||||
title: "Raw Get",
|
||||
category: "Lua",
|
||||
description: "Access a table entry without metamethods using rawget().",
|
||||
searchTags: ["rawget", "table", "lua"],
|
||||
inputs: [
|
||||
{ id: "table", name: "Table", direction: "input", kind: "table" },
|
||||
{ id: "key", name: "Key", direction: "input", kind: "any" },
|
||||
],
|
||||
outputs: [
|
||||
{ id: "value", name: "Value", direction: "output", kind: "any" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const tableValue = resolveValueInput("table", "{}");
|
||||
const key = resolveValueInput("key", "nil");
|
||||
return `rawget(${tableValue}, ${key})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
33
scripts/nodes/library/lua/rawSet.js
Normal file
33
scripts/nodes/library/lua/rawSet.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Writes a raw table entry using rawset().
|
||||
*/
|
||||
export const luaRawSetNode = createNodeModule(
|
||||
{
|
||||
id: "lua_rawset",
|
||||
title: "Raw Set",
|
||||
category: "Lua",
|
||||
description: "Assign a table entry without metamethods using rawset().",
|
||||
searchTags: ["rawset", "table", "lua"],
|
||||
inputs: [
|
||||
{ id: "exec_in", name: "Exec", direction: "input", kind: "exec" },
|
||||
{ id: "table", name: "Table", direction: "input", kind: "table" },
|
||||
{ id: "key", name: "Key", direction: "input", kind: "any" },
|
||||
{ id: "value", name: "Value", direction: "input", kind: "any" },
|
||||
],
|
||||
outputs: [
|
||||
{ id: "exec_out", name: "Exec", direction: "output", kind: "exec" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
emitExec: ({ indent, indentLevel, resolveValueInput, emitNextExec }) => {
|
||||
const tableValue = resolveValueInput("table", "{}");
|
||||
const key = resolveValueInput("key", "nil");
|
||||
const value = resolveValueInput("value", "nil");
|
||||
const line = `${indent(indentLevel)}rawset(${tableValue}, ${key}, ${value})`;
|
||||
return [line, ...emitNextExec("exec_out")];
|
||||
},
|
||||
}
|
||||
);
|
||||
35
scripts/nodes/library/lua/setMetatable.js
Normal file
35
scripts/nodes/library/lua/setMetatable.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Applies a metatable to a table via setmetatable().
|
||||
*/
|
||||
export const luaSetMetatableNode = createNodeModule(
|
||||
{
|
||||
id: "lua_setmetatable",
|
||||
title: "Set Metatable",
|
||||
category: "Lua",
|
||||
description: "Assign a metatable to a table using setmetatable().",
|
||||
searchTags: ["setmetatable", "metatable", "lua"],
|
||||
inputs: [
|
||||
{ id: "table", name: "Table", direction: "input", kind: "table" },
|
||||
{
|
||||
id: "metatable",
|
||||
name: "Metatable",
|
||||
direction: "input",
|
||||
kind: "table",
|
||||
defaultValue: "nil",
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{ id: "table_out", name: "Table", direction: "output", kind: "table" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const tableValue = resolveValueInput("table", "{}");
|
||||
const metatable = resolveValueInput("metatable", "nil");
|
||||
return `setmetatable(${tableValue}, ${metatable})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user