import 'package:libac_dart/omv/types/integer.dart'; import 'package:libac_dart/omv/types/key.dart'; import 'package:libac_dart/omv/types/list.dart'; import 'package:libac_dart/omv/types/rotation.dart'; import 'package:libac_dart/omv/types/string.dart'; import 'package:libac_dart/omv/types/vector.dart'; abstract class SLEvents { void at_rot_target( Integer iHandle, Rotation rTargetRotation, Rotation rCurrentRotation); void at_target( Integer iHandle, Vector vTargetPosition, Vector vCurrrentPosition); void attach(Key kAttached); void changed(Integer iChangedFlags); void collision(Integer iCollisionCount); void collision_end(Integer iCollisionCount); void collision_start(Integer iCollisionCount); void control(Key kID, Integer iLevels, Integer iEdges); void dataserver(Key kRequestID, string sData); void email(string sTime, string sAddress, string sSubject, string sBody, Integer iRemaining); void http_response( Key kRequestID, Integer iStatus, list lMetadata, string sBody); void http_request(Key kRequestID, string sMethod, string sBody); void land_collision(Vector vPosition); void land_collision_end(Vector vPosition); void land_collision_start(Vector vPosition); void link_message( Integer iSenderLinkIndex, Integer iNumber, string sText, Key kID); void linkset_data(Integer action, string name, string value); void listen(Integer iChannel, String sName, Key kID, String sText); void money(Key kPayerID, Integer iAmount); void moving_end(); void moving_start(); void no_sensor(); void not_at_rot_target(); void not_at_target(); void object_rez(Key kID); void on_rez(Integer iStartParameter); void path_update(Integer iType, list lReserved); void remote_data(Integer iEventType, Key kChannelID, Key kMessageID, string sSender, Integer iData, string sData); void run_time_permissions(Integer iPermissionsFlags); void sensor(Integer iSensedCount); void state_entry(); void state_exit(); void timer(); void touch(Integer iTouchesCount); void touch_end(Integer iTouchesCount); void touch_start(Integer iTouchesCount); void transaction_result(Key kID, Integer iSuccess, string sMessage); } /// Custom execution stack to mimic compilation behavior /// A script is composed of states, which have every event listed in SLEvents, or OSEvents which inherits SLEvents /// Each event will be composed of an execution stack. Custom function can be defined, they shall be stored in a dictionary with their execution stack /// /// The execution stack should execute each function contained within in sequential order. /// /// The execution stack cannot be altered once created, it is designed to be assembled, then executed, to change it, one must create a new stack. /// /// Variables are defined in the SLMemoryStack. /// On parse, a variable will be created, then inserted into the memory stack. Naming convention is as follows. /// global: g_ /// global_function: g_f /// local: __ /// /// Any function here will need to be parsed properly to edit the memory stack if applicable before adding it to the execution stack /// /// NOTE: Dart does not have a JIT Compiler that can at runtime without the Dart SDK compile a dynamic dart script against the running application /// To make up for this, we must put in place a structure that would allow parsing the script and still allowing execution within our own codebase. class SLExecutionStack { List _stack = []; void add(Function fnc) { _stack.add(fnc); } void execute() { for (var f in _stack) { f.call(); } } } /// This memory stack is meant to be allocated per script. See naming convention specified in SLExecutionStack documentation /// /// NOTE: If memory is not present, it will return a blank string class SLMemoryStack { Map _memory = {}; void set(String name, dynamic memory) { _memory[name] = memory; } dynamic get(String name) { return _memory[name] ?? ""; } }