Pixel-Composer/scripts/node_lua_global/node_lua_global.gml

40 lines
1.2 KiB
Plaintext
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Lua_Global(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
2023-01-25 06:49:00 +01:00
name = "Lua Global";
2023-01-04 02:30:04 +01:00
preview_channel = 1;
2024-08-18 09:13:41 +02:00
newInput(0, nodeValue_Text("Lua code", self, "", o_dialog_lua_reference))
2023-09-07 20:59:14 +02:00
.setDisplay(VALUE_DISPLAY.codeLUA);
2023-01-04 02:30:04 +01:00
2024-08-18 06:16:20 +02:00
newInput(1, nodeValue_Enum_Scroll("Run order", self, 0, [ "On start", "Every frame" ]));
2023-01-04 02:30:04 +01:00
2024-08-20 10:15:53 +02:00
newInput(2, nodeValue("Execution thread", self, CONNECT_TYPE.input, VALUE_TYPE.node, noone))
2023-01-04 02:30:04 +01:00
.setVisible(false, true);
2024-08-08 06:57:51 +02:00
outputs[0] = nodeValue_Output("Execution thread", self, VALUE_TYPE.node, noone );
2023-01-04 02:30:04 +01:00
input_display_list = [
2024-01-23 14:40:03 +01:00
["Main", false], 2, 1, 0,
2023-01-09 03:14:20 +01:00
];
2023-01-04 02:30:04 +01:00
2024-01-23 14:40:03 +01:00
lua_state = lua_create();
2023-03-07 14:29:47 +01:00
is_beginning = false;
2023-01-04 02:30:04 +01:00
2024-08-18 05:10:39 +02:00
static getState = function() {
2024-08-08 06:57:51 +02:00
if(inputs[2].value_from == noone) return lua_state;
return inputs[2].value_from.node.getState();
2024-08-18 05:10:39 +02:00
}
2023-01-04 02:30:04 +01:00
2024-08-18 05:10:39 +02:00
static update = function(frame = CURRENT_FRAME) {
var _code = getInputData(0);
var _type = getInputData(1);
2024-01-23 14:40:03 +01:00
update_on_frame = _type;
2023-01-04 02:30:04 +01:00
2023-03-08 07:35:51 +01:00
lua_projectData(getState());
2024-01-23 14:40:03 +01:00
try { lua_add_code(getState(), _code); }
catch(e) { noti_warning(exception_print(e),, self); }
2024-05-23 14:40:30 +02:00
}
2024-08-18 05:10:39 +02:00
static onDestroy = function() { lua_state_destroy(lua_state); }
static onRestore = function() { lua_state = lua_create(); }
2023-01-04 02:30:04 +01:00
}