Skip to content

Commit ca52eb3

Browse files
chore: autopublish 2023-03-10T03:21:26Z
1 parent 3479200 commit ca52eb3

18 files changed

Lines changed: 379 additions & 188 deletions

docs/library/general_library.md

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
- [is_font_smufl_font(font_info)](#is_font_smufl_font)
2222
- [simple_input(title, text)](#simple_input)
2323
- [is_finale_object(object)](#is_finale_object)
24+
- [get_parent_class(classname)](#get_parent_class)
25+
- [get_class_name(object)](#get_class_name)
2426
- [system_indent_set_to_prefs(system, page_format_prefs)](#system_indent_set_to_prefs)
2527
- [calc_script_name(include_extension)](#calc_script_name)
2628
- [get_default_music_font_name()](#get_default_music_font_name)
@@ -349,13 +351,49 @@ Attempts to determine if an object is a Finale object through ducktyping
349351
| ----------- | ----------- |
350352
| `bool` | |
351353

354+
### get_parent_class
355+
356+
```lua
357+
library.get_parent_class(classname)
358+
```
359+
360+
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/general_library.lua#L491)
361+
362+
Returns the name of the parent of a class.
363+
364+
| Input | Type | Description |
365+
| ----- | ---- | ----------- |
366+
| `classname` | `string` | |
367+
368+
| Return type | Description |
369+
| ----------- | ----------- |
370+
| `string \\| nil` | The parent classname or `nil` if the class has no parent (ie `__FCBase`). |
371+
372+
### get_class_name
373+
374+
```lua
375+
library.get_class_name(object)
376+
```
377+
378+
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/general_library.lua#L524)
379+
380+
Returns the real class name of a Finale object. Some classes in older JW/RGPLua versions have incorrect class names, so this function attempts to resolve them with ducktyping
381+
382+
| Input | Type | Description |
383+
| ----- | ---- | ----------- |
384+
| `object` | `__FCBase` | |
385+
386+
| Return type | Description |
387+
| ----------- | ----------- |
388+
| `string` | |
389+
352390
### system_indent_set_to_prefs
353391

354392
```lua
355393
library.system_indent_set_to_prefs(system, page_format_prefs)
356394
```
357395

358-
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/general_library.lua#L493)
396+
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/general_library.lua#L556)
359397

360398
Sets the system to match the indentation in the page preferences currently in effect. (For score or part.)
361399
The page preferences may be provided optionally to avoid loading them for each call.
@@ -375,7 +413,7 @@ The page preferences may be provided optionally to avoid loading them for each c
375413
library.calc_script_name(include_extension)
376414
```
377415

378-
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/general_library.lua#L518)
416+
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/general_library.lua#L581)
379417

380418
Returns the running script name, with or without extension.
381419

@@ -393,7 +431,7 @@ Returns the running script name, with or without extension.
393431
library.get_default_music_font_name()
394432
```
395433

396-
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/general_library.lua#L547)
434+
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/general_library.lua#L610)
397435

398436
Fetches the default music font from document options and processes the name into a usable format.
399437

docs/library/mixin.md

Lines changed: 61 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ Below is a basic template for creating an `FCM` mixin. Replace the example metho
181181
```lua
182182
-- Include the mixin namespace and helper methods (include any additional libraries below)
183183
local mixin = require("library.mixin")
184+
local mixin_helper = require("library.mixin_helper")
184185

185186
-- Table for storing private data for this mixin
186187
local private = setmetatable({}, {__mode = "k"})
@@ -203,7 +204,7 @@ end
203204
function public:SetExample(value)
204205
-- Ensure argument is the correct type for testing
205206
-- The argument number is 2 because when using a colon in the method signature, it will automatically be passed `self` as the first argument.
206-
mixin.assert_argument(value, "string", 2)
207+
mixin_helper.assert_argument_type(2, value, "string")
207208

208209
private[self].ExamplePrivateProperty = value
209210
end
@@ -227,6 +228,7 @@ Below is a template for creating an `FCX` mixin. It is almost identical to defin
227228
```lua
228229
-- Include the mixin namespace and helper methods (include any additional libraries below)
229230
local mixin = require("library.mixin")
231+
local mixin_helper = require("library.mixin_helper")
230232

231233
-- Table for storing private data for this mixin
232234
local private = setmetatable({}, {__mode = "k"})
@@ -280,155 +282,146 @@ Personal mixins take precedence over public mixins, so if a mixin with the same
280282

281283
## Functions
282284

285+
- [is_fc_class_name(class_name)](#is_fc_class_name)
286+
- [is_fcm_class_name(class_name)](#is_fcm_class_name)
287+
- [is_fcx_class_name(class_name)](#is_fcx_class_name)
288+
- [fc_to_fcm_class_name(class_name)](#fc_to_fcm_class_name)
289+
- [fcm_to_fc_class_name(class_name)](#fcm_to_fc_class_name)
283290
- [subclass(object, class_name)](#subclass)
284-
- [is_instance_of(object, class_name)](#is_instance_of)
285-
- [assert_argument(value, expected_type, argument_number)](#assert_argument)
286-
- [force_assert_argument(value, expected_type, argument_number)](#force_assert_argument)
287-
- [assert(condition, message, no_level)](#assert)
288-
- [force_assert(condition, message, no_level)](#force_assert)
289291
- [UI()](#ui)
290292
- [eachentry(region, layer)](#eachentry)
291293

292-
### subclass
294+
### is_fc_class_name
293295

294296
```lua
295-
mixin.subclass(object, class_name)
297+
mixin.is_fc_class_name(class_name)
296298
```
297299

298-
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/mixin.lua#L850)
300+
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/mixin.lua#L740)
299301

300302

301-
Takes a mixin-enabled finale object and migrates it to an `FCX` subclass. Any conflicting property or method names will be overwritten.
302-
303-
If the object is not mixin-enabled or the current `MixinClass` is not a parent of `class_name`, then an error will be thrown.
304-
If the current `MixinClass` is the same as `class_name`, this function will do nothing.
303+
Checks if a class name is an `FC` class name.
305304

306305

307306
| Input | Type | Description |
308307
| ----- | ---- | ----------- |
309-
| `object` | `__FCMBase` | |
310-
| `class_name` | `string` | FCX class name. |
308+
| `class_name` | `string` | |
311309

312310
| Return type | Description |
313311
| ----------- | ----------- |
314-
| `__FCMBase\\|nil` | The object that was passed with mixin applied. |
312+
| `boolean` | |
315313

316-
### is_instance_of
314+
### is_fcm_class_name
317315

318316
```lua
319-
mixin.is_instance_of(object, class_name)
317+
mixin.is_fcm_class_name(class_name)
320318
```
321319

322-
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/mixin.lua#L866)
320+
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/mixin.lua#L750)
323321

324322

325-
Checks if an object is an instance of a class.
326-
Conditions:
327-
- Parent cannot be instance of child.
328-
- `FC` object cannot be an instance of an `FCM` or `FCX` class
329-
- `FCM` object cannot be an instance of an `FCX` class
330-
- `FCX` object cannot be an instance of an `FC` class
323+
Checks if a class name is an `FCM` class name.
331324

332325

333326
| Input | Type | Description |
334327
| ----- | ---- | ----------- |
335-
| `object` | `__FCBase` | Any finale object, including mixin enabled objects. |
336-
| `class_name` | `string` | An `FC`, `FCM`, or `FCX` class name. Can be the name of a parent class. |
328+
| `class_name` | `string` | |
337329

338330
| Return type | Description |
339331
| ----------- | ----------- |
340332
| `boolean` | |
341333

342-
### assert_argument
334+
### is_fcx_class_name
343335

344336
```lua
345-
mixin.assert_argument(value, expected_type, argument_number)
337+
mixin.is_fcx_class_name(class_name)
346338
```
347339

348-
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/mixin.lua#L937)
349-
350-
351-
Asserts that an argument to a mixin method is the expected type(s). This should only be used within mixin methods as the function name will be inserted automatically.
340+
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/mixin.lua#L760)
352341

353-
NOTE: For performance reasons, this function will only assert if in debug mode (ie `finenv.DebugEnabled == true`). If assertions are always required, use `force_assert_argument` instead.
354342

355-
If not a valid type, will throw a bad argument error at the level above where this function is called.
356-
Types can be Lua types (eg `string`, `number`, `bool`, etc), finale class (eg `FCString`, `FCMeasure`, etc), or mixin class (eg `FCMString`, `FCMMeasure`, etc)
357-
Parent classes cannot be specified as this function does not examine the class hierarchy.
358-
359-
Note that mixin classes may satisfy the condition for the underlying `FC` class.
360-
For example, if the expected type is `FCString`, an `FCMString` object will pass the test, but an `FCXString` object will not.
361-
If the expected type is `FCMString`, an `FCXString` object will pass the test but an `FCString` object will not.
343+
Checks if a class name is an `FCX` class name.
362344

363345

364346
| Input | Type | Description |
365347
| ----- | ---- | ----------- |
366-
| `value` | `mixed` | The value to test. |
367-
| `expected_type` | `string\|table` | If there are multiple valid types, pass a table of strings. |
368-
| `argument_number` | `number` | The REAL argument number for the error message (self counts as #1). |
348+
| `class_name` | `string` | |
369349

370-
### force_assert_argument
350+
| Return type | Description |
351+
| ----------- | ----------- |
352+
| `boolean` | |
353+
354+
### fc_to_fcm_class_name
371355

372356
```lua
373-
mixin.force_assert_argument(value, expected_type, argument_number)
357+
mixin.fc_to_fcm_class_name(class_name)
374358
```
375359

376-
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/mixin.lua#L973)
360+
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/mixin.lua#L770)
377361

378362

379-
The same as `assert_argument` except this function always asserts, regardless of whether debug mode is enabled.
363+
Converts an `FC` class name to an `FCM` class name.
380364

381365

382366
| Input | Type | Description |
383367
| ----- | ---- | ----------- |
384-
| `value` | `mixed` | The value to test. |
385-
| `expected_type` | `string\|table` | If there are multiple valid types, pass a table of strings. |
386-
| `argument_number` | `number` | The REAL argument number for the error message (self counts as #1). |
368+
| `class_name` | `string` | |
387369

388-
### assert
370+
| Return type | Description |
371+
| ----------- | ----------- |
372+
| `string` | |
373+
374+
### fcm_to_fc_class_name
389375

390376
```lua
391-
mixin.assert(condition, message, no_level)
377+
mixin.fcm_to_fc_class_name(class_name)
392378
```
393379

394-
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/mixin.lua#L985)
380+
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/mixin.lua#L780)
395381

396382

397-
Asserts a condition in a mixin method. If the condition is false, an error is thrown one level above where this function is called.
398-
Only asserts when in debug mode. If assertion is required on all executions, use `force_assert` instead
383+
Converts an `FCM` class name to an `FC` class name.
399384

400385

401386
| Input | Type | Description |
402387
| ----- | ---- | ----------- |
403-
| `condition` | `any` | Can be any value or expression. If a function, it will be called (with zero arguments) and the result will be tested. |
404-
| `message` | `string` | The error message. |
405-
| `no_level` (optional) | `boolean` | If true, error will be thrown with no level (ie level 0) |
388+
| `class_name` | `string` | |
406389

407-
### force_assert
390+
| Return type | Description |
391+
| ----------- | ----------- |
392+
| `string` | |
393+
394+
### subclass
408395

409396
```lua
410-
mixin.force_assert(condition, message, no_level)
397+
mixin.subclass(object, class_name)
411398
```
412399

413-
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/mixin.lua#L1004)
400+
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/mixin.lua#L794)
414401

415402

416-
The same as `assert` except this function always asserts, regardless of whether debug mode is enabled.
403+
Takes a mixin-enabled finale object and migrates it to an `FCX` subclass. Any conflicting property or method names will be overwritten.
404+
405+
If the object is not mixin-enabled or the current `MixinClass` is not a parent of `class_name`, then an error will be thrown.
406+
If the current `MixinClass` is the same as `class_name`, this function will do nothing.
417407

418408

419409
| Input | Type | Description |
420410
| ----- | ---- | ----------- |
421-
| `condition` | `any` | Can be any value or expression. |
422-
| `message` | `string` | The error message. |
423-
| `no_level` (optional) | `boolean` | If true, error will be thrown with no level (ie level 0) |
411+
| `object` | `__FCMBase` | |
412+
| `class_name` | `string` | FCX class name. |
413+
414+
| Return type | Description |
415+
| ----------- | ----------- |
416+
| `__FCMBase\\|nil` | The object that was passed with mixin applied. |
424417

425418
### UI
426419

427420
```lua
428421
mixin.UI()
429422
```
430423

431-
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/mixin.lua#L1019)
424+
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/mixin.lua#L803)
432425

433426

434427
Returns a mixin enabled UI object from `finenv.UI`
@@ -444,7 +437,7 @@ Returns a mixin enabled UI object from `finenv.UI`
444437
mixin.eachentry(region, layer)
445438
```
446439

447-
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/mixin.lua#L1032)
440+
[View source](https://github.com/finale-lua/lua-scripts/tree/master/src/library/mixin.lua#L816)
448441

449442

450443
A modified version of the JW/RGPLua `eachentry` function that allows items to be stored and used outside of a loop.

0 commit comments

Comments
 (0)