-
Hey all, I want to declare a function from a global extension where a parameter should hold the value of a record. E.g. suppose I have following function that I want to declare:
How would I be able to declare MP.CreateEventTimer("testEvent", 1000, MP.CallStrategy.BestEffort)
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
@PedroHase You can do something like this: -- declare MP
global record MP
record CallStrategyType
-- what do call strategies have in common?
end
record CallStrategy
BestEffort: CallStrategyType
Precise: CallStrategyType
end
CreateEventTimer: function(eventName: string, timerInMS: number, strategy: MP.CallStrategyType): nil
end
-- test CreateEventTimer
MP.CreateEventTimer("testEvent", 1000, MP.CallStrategy.Precise) |
Beta Was this translation helpful? Give feedback.
-
With the code in the latest master (which fixes typechecking of enum keys in maps when using dot-notation), you could alternatively declare CallStrategy as a map like this: -- declare MP
global record MP
record CallStrategyType
-- what do call strategies have in common?
end
enum CallStrategyName
"BestEffort"
"Precise"
end
CallStrategy: {CallStrategyName:CallStrategyType}
CreateEventTimer: function(eventName: string, timerInMS: number, strategy: MP.CallStrategyType): nil
end
-- test CreateEventTimer
MP.CreateEventTimer("testEvent", 1000, MP.CallStrategy.Precise) |
Beta Was this translation helpful? Give feedback.
@PedroHase You can do something like this: