2023-02-28 15:43:01 +07:00
|
|
|
function Node_Lua_Global(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
2023-01-25 12:49:00 +07:00
|
|
|
name = "Lua Global";
|
2023-01-04 08:30:04 +07:00
|
|
|
preview_channel = 1;
|
|
|
|
|
2023-02-14 11:32:32 +07:00
|
|
|
inputs[| 0] = nodeValue("Lua code", self, JUNCTION_CONNECT.input, VALUE_TYPE.text, "", o_dialog_lua_reference)
|
2023-09-07 20:59:14 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY.codeLUA);
|
2023-01-04 08:30:04 +07:00
|
|
|
|
2023-02-14 11:32:32 +07:00
|
|
|
inputs[| 1] = nodeValue("Run order", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
|
2023-01-04 08:30:04 +07:00
|
|
|
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "On start", "Every frame" ]);
|
|
|
|
|
2023-02-14 11:32:32 +07:00
|
|
|
inputs[| 2] = nodeValue("Execution thread", self, JUNCTION_CONNECT.input, VALUE_TYPE.node, noone)
|
2023-01-04 08:30:04 +07:00
|
|
|
.setVisible(false, true);
|
|
|
|
|
2023-02-14 11:32:32 +07:00
|
|
|
outputs[| 0] = nodeValue("Execution thread", self, JUNCTION_CONNECT.output, VALUE_TYPE.node, noone );
|
2023-01-04 08:30:04 +07:00
|
|
|
|
|
|
|
input_display_list = [
|
2024-01-23 20:40:03 +07:00
|
|
|
["Main", false], 2, 1, 0,
|
2023-01-09 09:14:20 +07:00
|
|
|
];
|
2023-01-04 08:30:04 +07:00
|
|
|
|
2024-01-23 20:40:03 +07:00
|
|
|
lua_state = lua_create();
|
2023-03-07 20:29:47 +07:00
|
|
|
is_beginning = false;
|
2023-01-04 08:30:04 +07:00
|
|
|
|
2023-11-23 08:32:26 +07:00
|
|
|
static getState = function() { #region
|
2023-10-27 18:55:31 +07:00
|
|
|
if(inputs[| 2].isLeaf()) return lua_state;
|
2023-01-04 08:30:04 +07:00
|
|
|
return inputs[| 2].value_from.node.getState();
|
2023-11-23 08:32:26 +07:00
|
|
|
} #endregion
|
2023-01-04 08:30:04 +07:00
|
|
|
|
2023-11-23 08:32:26 +07:00
|
|
|
static update = function(frame = CURRENT_FRAME) { #region
|
2023-10-02 13:57:44 +07:00
|
|
|
var _code = getInputData(0);
|
|
|
|
var _type = getInputData(1);
|
2024-01-23 20:40:03 +07:00
|
|
|
update_on_frame = _type;
|
2023-01-04 08:30:04 +07:00
|
|
|
|
2023-03-08 13:35:51 +07:00
|
|
|
lua_projectData(getState());
|
|
|
|
|
2024-01-23 20:40:03 +07:00
|
|
|
try { lua_add_code(getState(), _code); }
|
|
|
|
catch(e) { noti_warning(exception_print(e),, self); }
|
2023-11-23 08:32:26 +07:00
|
|
|
} #endregion
|
2023-03-19 15:17:39 +07:00
|
|
|
|
2023-11-23 08:32:26 +07:00
|
|
|
static onDestroy = function() { #region
|
2023-03-08 13:35:51 +07:00
|
|
|
lua_state_destroy(lua_state);
|
2023-11-23 08:32:26 +07:00
|
|
|
} #endregion
|
2023-01-04 08:30:04 +07:00
|
|
|
}
|