URI: 
       Catched up with lua documentation. - icy_draw - icy_draw is the successor to mystic draw. fork / mirror
  HTML git clone https://git.drkhsh.at/icy_draw.git
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 289214e84d561bb120f43f9431cf93df11ee6ef1
   DIR parent 0decc48ebc259a6a537c344e34e2e84a7a06b09a
  HTML Author: Mike Krüger <mkrueger@posteo.de>
       Date:   Mon, 25 Sep 2023 07:00:50 +0200
       
       Catched up with lua documentation.
       
       Diffstat:
         M doc/lua_api.md                      |      87 ++++++++++++++++---------------
         M src/plugins/mod.rs                  |      50 +++++++++++++++++++------------
       
       2 files changed, 76 insertions(+), 61 deletions(-)
       ---
   DIR diff --git a/doc/lua_api.md b/doc/lua_api.md
       @@ -1,15 +1,28 @@
        # LUA API
        
       -Lua is used as scripting language for the animation engine.
       +Lua is used as scripting language for the animation engine and plugin language
        
        ## Global variables
       +### Animations only
        
        | Variable     | Description
        |--------------|--------------------------------------
        | `cur_frame`  | Number of current frame (1 based)
        
       +### Plugins only
       +| Variable     | Description
       +|--------------|--------------------------------------
       +| `buf`        | Current buffer
       +| `start_x`    | Current area start x
       +| `end_x`      | Current area end x
       +| `start_y`    | Current area start y
       +| `end_y`      | Current area end y
       +
       +The current area is the whole layer or the selected portion of it. The coordinates are current layer coordinates.
        ## Global function
        
       +### Animations only
       +
        | Function                               | Returns    | Description
        |----------------------------------------|------------|--------------------------
        | `new_buffer(width: i32, height: i32)`  |  Buffer    | Create new, empty buffer with given get_size
       @@ -35,6 +48,7 @@ Lua is used as scripting language for the animation engine.
        
        ### Methods
        
       +
        | Method                                 | Returns | Description
        |----------------------------------------|---------|--------------------------
        | `clear()`                              | -       | clears the buffer & resets caret
       @@ -56,49 +70,39 @@ Input/Output
        | `fg_rgb(#rrggbb)`                      | u32     | Sets the caret fg rgb color with html style notation , returns color palette number
        | `bg_rgb(r, g, b)`                      | u32     | Sets the caret bg rgb color, returns color palette number
        | `bg_rgb(#rrggbb)`                      | u32     | Sets the caret bg rgb color with html style notation , returns color palette number
       -| `set_char(x, y, ch)`                   | -       | Sets a specific char at a given position (uses caret color)
       -| `get_char(x, y)`                       | char    | Gets a specific char at a given position
       -| `pickup_char(x, y)`                    | char    | Like get char but sets all attributes to the char attributes
       +| `set_char(x, y, string)`               | -       | Sets a specific char at a given position (uses caret color)
       +| `get_char(x, y)`                       | string  | Gets a specific char at a given position
       +| `pickup_char(x, y)`                    | string  | Like get char but sets all attributes to the char attributes
        | `get_fg(x, y)`                         | u32     | Gets the foreground at a given positon
        | `set_fg(x, y, fg)`                     | -       | Sets a specific foreground at a given layer position
        | `get_bg(x, y)`                         | u32     | Gets the background at a given positon
        | `set_bg(x, y, bg)`                     | -       | Sets a specific foreground at a given layer position
        | `print(string)`                        | -       | Prints a string at caret position, advances caret.
        
       -
       -## CP437 - Unicode table:
       -
       -|Offset|0|1|2|3|4|5|6|7|
       -|---|-|-|-|-|-|-|-|-
       -|  0| |☺|☻|♥|♦|♣|♠|•
       -|  8|◘|○|◙|♂|♀|♪|♫|☼
       -| 16|►|◄|↕|‼|¶|§|▬|↨
       -| 24|↑|↓|→|←|∟|↔|▲|▼
       -| 32| |!|"|#|$|%|&|'
       -| 40|(|)|*|+|,|-|.|/
       -| 48|0|1|2|3|4|5|6|7
       -| 56|8|9|:|;|<|=|>|?
       -| 64|@|A|B|C|D|E|F|G
       -| 72|H|I|J|K|L|M|N|O
       -| 80|P|Q|R|S|T|U|V|W
       -| 88|X|Y|Z|[|\|]|^|_
       -| 96|`|a|b|c|d|e|f|g
       -|104|h|i|j|k|l|m|n|o
       -|112|p|q|r|s|t|u|v|w
       -|120|x|y|z|{|||}|~|
       -|128|Ç|ü|é|â|ä|à|å|ç
       -|136|ê|ë|è|ï|î|ì|Ä|Å
       -|144|É|æ|Æ|ô|ö|ò|û|ù
       -|152|ÿ|Ö|Ü|¢|£|¥|₧|ƒ
       -|160|á|í|ó|ú|ñ|Ñ|ª|º
       -|168|¿|⌐|¬|½|¼|¡|«|»
       -|176|░|▒|▓|│|┤|╡|╢|╖
       -|184|╕|╣|║|╗|╝|╜|╛|┐
       -|192|└|┴|┬|├|─|┼|╞|╟
       -|200|╚|╔|╩|╦|╠|═|╬|╧
       -|208|╨|╤|╥|╙|╘|╒|╓|╫
       -|216|╪|┘|┌|█|▄|▌|▐|▀
       -|224|α|ß|Γ|π|Σ|σ|µ|τ
       -|232|Φ|Θ|Ω|δ|∞|φ|ε|∩
       -|240|≡|±|≥|≤|⌠|⌡|÷|≈
       -|248|°|∙|·|√|ⁿ|²|■|
       -\ No newline at end of file
       +Note for representing chars strings with length 1 is used. Additional chars are ignored. Empty strings lead to error.
       +LUA uses unicode as char representation which is converted to the according buffer type.
       +
       +## CP437 - Unicode table
       +
       +The LUA API useses unicode. This makes scripts more flexibile accross different buffer types. For CP437 this conversion table is used:
       +
       +|Offset|0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|
       +|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-
       +|  0|NUL|☺ (263A)|☻ (263B)|♥ (2665)|♦ (2666)|♣ (2663)|♠ (2660)|• (2022)|◘ (25D8)|○ (25CB)|◙ (25D9)|♂ (2642)|♀ (2640)|♪ (266A)|♫ (266B)|☼ (263C)
       +| 16|► (25BA)|◄ (25C4)|↕ (2195)|‼ (203C)|¶ (00B6)|§ (00A7)|▬ (25AC)|↨ (21A8)|↑ (2191)|↓ (2193)|→ (2192)|← (2190)|∟ (221F)|↔ (2194)|▲ (25B2)|▼ (25BC)
       +| 32|SP|!|"|#|$|%|&|'|(|)|*|+|,|-|.|/
       +| 48|0|1|2|3|4|5|6|7|8|9|:|;|<|=|>|?
       +| 64|@|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O
       +| 80|P|Q|R|S|T|U|V|W|X|Y|Z|[|\|]|^|_
       +| 96|`|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o
       +|112|p|q|r|s|t|u|v|w|x|y|z|{|||}|~|
       +|128|Ç (00C7)|ü (00FC)|é (00E9)|â (00E2)|ä (00E4)|à (00E0)|å (00E5)|ç (00E7)|ê (00EA)|ë (00EB)|è (00E8)|ï (00EF)|î (00EE)|ì (00EC)|Ä (00C4)|Å (00C5)
       +|144|É (00C9)|æ (00E6)|Æ (00C6)|ô (00F4)|ö (00F6)|ò (00F2)|û (00FB)|ù (00F9)|ÿ (00FF)|Ö (00D6)|Ü (00DC)|¢ (00A2)|£ (00A3)|¥ (00A5)|₧ (20A7)|ƒ (0192)
       +|160|á (00E1)|í (00ED)|ó (00F3)|ú (00FA)|ñ (00F1)|Ñ (00D1)|ª (00AA)|º (00BA)|¿ (00BF)|⌐ (2310)|¬ (00AC)|½ (00BD)|¼ (00BC)|¡ (00A1)|« (00AB)|» (00BB)
       +|176|░ (2591)|▒ (2592)|▓ (2593)|│ (2502)|┤ (2524)|╡ (2561)|╢ (2562)|╖ (2556)|╕ (2555)|╣ (2563)|║ (2551)|╗ (2557)|╝ (255D)|╜ (255C)|╛ (255B)|┐ (2510)
       +|192|└ (2514)|┴ (2534)|┬ (252C)|├ (251C)|─ (2500)|┼ (253C)|╞ (255E)|╟ (255F)|╚ (255A)|╔ (2554)|╩ (2569)|╦ (2566)|╠ (2560)|═ (2550)|╬ (256C)|╧ (2567)
       +|208|╨ (2568)|╤ (2564)|╥ (2565)|╙ (2559)|╘ (2558)|╒ (2552)|╓ (2553)|╫ (256B)|╪ (256A)|┘ (2518)|┌ (250C)|█ (2588)|▄ (2584)|▌ (258C)|▐ (2590)|▀ (2580)
       +|224|α (03B1)|ß (00DF)|Γ (0393)|π (03C0)|Σ (03A3)|σ (03C3)|µ (00B5)|τ (03C4)|Φ (03A6)|Θ (0398)|Ω (03A9)|δ (03B4)|∞ (221E)|φ (03C6)|ε (03B5)|∩ (2229)
       +|240|≡ (2261)|± (00B1)|≥ (2265)|≤ (2264)|⌠ (2320)|⌡ (2321)|÷ (00F7)|≈ (2248)|° (00B0)|∙ (2219)|· (00B7)|√ (221A)|ⁿ (207F)|² (00B2)|■ (25A0)|  (00A0)
       +
       +Source: <https://en.wikipedia.org/wiki/Code_page_437>
   DIR diff --git a/src/plugins/mod.rs b/src/plugins/mod.rs
       @@ -1,7 +1,7 @@
        use std::{fs, path::Path, sync::Arc};
        
        use i18n_embed_fl::fl;
       -use icy_engine::{AttributedChar, Position, TextPane, BufferParser};
       +use icy_engine::{AttributedChar, BufferParser, Position, TextPane};
        use mlua::{Lua, UserData};
        use regex::Regex;
        use walkdir::WalkDir;
       @@ -125,10 +125,14 @@ impl LuaBufferView {
                let buffer_type = self.buffer_view.lock().get_buffer().buffer_type;
                let ch = match buffer_type {
                    icy_engine::BufferType::Unicode => ch,
       -            icy_engine::BufferType::CP437 => icy_engine::ascii::Parser::default().convert_from_unicode(ch, self.buffer_view.lock().get_caret().get_font_page()),
       -            icy_engine::BufferType::Petscii => icy_engine::petscii::Parser::default().convert_from_unicode(ch, self.buffer_view.lock().get_caret().get_font_page()),
       -            icy_engine::BufferType::Atascii => icy_engine::atascii::Parser::default().convert_from_unicode(ch, self.buffer_view.lock().get_caret().get_font_page()),
       -            icy_engine::BufferType::Viewdata => icy_engine::viewdata::Parser::default().convert_from_unicode(ch, self.buffer_view.lock().get_caret().get_font_page()),
       +            icy_engine::BufferType::CP437 => icy_engine::ascii::Parser::default()
       +                .convert_from_unicode(ch, self.buffer_view.lock().get_caret().get_font_page()),
       +            icy_engine::BufferType::Petscii => icy_engine::petscii::Parser::default()
       +                .convert_from_unicode(ch, self.buffer_view.lock().get_caret().get_font_page()),
       +            icy_engine::BufferType::Atascii => icy_engine::atascii::Parser::default()
       +                .convert_from_unicode(ch, self.buffer_view.lock().get_caret().get_font_page()),
       +            icy_engine::BufferType::Viewdata => icy_engine::viewdata::Parser::default()
       +                .convert_from_unicode(ch, self.buffer_view.lock().get_caret().get_font_page()),
                };
                Ok(ch)
            }
       @@ -137,10 +141,18 @@ impl LuaBufferView {
                let buffer_type = self.buffer_view.lock().get_buffer().buffer_type;
                let ch = match buffer_type {
                    icy_engine::BufferType::Unicode => ch.ch,
       -            icy_engine::BufferType::CP437 => icy_engine::ascii::Parser::default().convert_to_unicode(ch),
       -            icy_engine::BufferType::Petscii => icy_engine::petscii::Parser::default().convert_to_unicode(ch),
       -            icy_engine::BufferType::Atascii => icy_engine::atascii::Parser::default().convert_to_unicode(ch),
       -            icy_engine::BufferType::Viewdata => icy_engine::viewdata::Parser::default().convert_to_unicode(ch),
       +            icy_engine::BufferType::CP437 => {
       +                icy_engine::ascii::Parser::default().convert_to_unicode(ch)
       +            }
       +            icy_engine::BufferType::Petscii => {
       +                icy_engine::petscii::Parser::default().convert_to_unicode(ch)
       +            }
       +            icy_engine::BufferType::Atascii => {
       +                icy_engine::atascii::Parser::default().convert_to_unicode(ch)
       +            }
       +            icy_engine::BufferType::Viewdata => {
       +                icy_engine::viewdata::Parser::default().convert_to_unicode(ch)
       +            }
                };
                ch.to_string()
            }
       @@ -299,10 +311,7 @@ impl UserData for LuaBufferView {
                    this.buffer_view
                        .lock()
                        .get_edit_state_mut()
       -                .set_char(
       -                    (x, y),
       -                    ch,
       -                )
       +                .set_char((x, y), ch)
                        .unwrap();
                    Ok(())
                });
       @@ -346,12 +355,14 @@ impl UserData for LuaBufferView {
                    }
        
                    let ch = this.buffer_view.lock().get_buffer_mut().layers[cur_layer].get_char((x, y));
       -            this.buffer_view.lock().get_caret_mut().set_attr(ch.attribute);
       +            this.buffer_view
       +                .lock()
       +                .get_caret_mut()
       +                .set_attr(ch.attribute);
        
                    Ok(this.convert_to_unicode(ch))
                });
        
       -
                methods.add_method_mut("set_fg", |_, this, (x, y, col): (i32, i32, u32)| {
                    let cur_layer = this
                        .buffer_view
       @@ -444,10 +455,11 @@ impl UserData for LuaBufferView {
                        let mut pos = this.buffer_view.lock().get_caret_mut().get_position();
                        let attribute = this.buffer_view.lock().get_caret_mut().get_attribute();
                        let ch = AttributedChar::new(this.convert_from_unicode(c.to_string())?, attribute);
       -                let _ = this.buffer_view.lock().get_edit_state_mut().set_char(
       -                    pos,
       -                    ch,
       -                );
       +                let _ = this
       +                    .buffer_view
       +                    .lock()
       +                    .get_edit_state_mut()
       +                    .set_char(pos, ch);
                        pos.x += 1;
                        this.buffer_view.lock().get_caret_mut().set_position(pos);
                    }