Вверх ↑
Ответов: 2059
Рейтинг: 132
#1: 2017-12-01 10:12:20 ЛС | профиль | цитата
andrestudio, а зачем делать переходник, если достаточно просто ошибку исправить?
Всё гораздо проще:
// Control := _NewControl(Fparent, 'SCINTILLA', WS_CHILD or WS_VISIBLE, false, nil);
Control := _NewCommonControl(Fparent, 'SCINTILLA', WS_CHILD or WS_VISIBLE, false, nil);


Add(MainForm,9524590,238,91)
{
Width=576
Height=481
}
Add(Scintilla,13351448,399,203)
{
Width=568
Height=454
Align=5
Font=[Courier New,11,0,0,204]
Layout="mainh"
HeightScale=99
Strings=#20:require "CLRPackage"|29:import "System.Windows.Forms"|23:import "System.Drawing"|59:local Directory = luanet.import_type("System.IO.Directory")|49:local Path = luanet.import_type("System.IO.Path")|49:local File = luanet.import_type("System.IO.File")|27:local append = table.insert|39:local ferr = io.stderr -- for debugging|0:|61:----------- some generally useful functions -----------------|78:--- Can be used to set multiple properties of an object, by supplying a table.|59:-- e.g. set(button,{Text="Click Me",Dock = DockStyle.Fill})|24:function set (obj,props)|30: for k,v in pairs(props) do|29: if type(k) == 'string' then|13: obj[k] = v|5: end|4: end|3:end|0:|60:--- works like AddRange, except it takes a table of controls|43:-- e.g add_controls(form,{button1,button2})|34:function add_controls (ctrl,ctrls)|30: for k,v in pairs(ctrls) do|25: ctrl.Controls:Add(v)|4: end|3:end|0:|38:function ShowMessageBox (caption,icon)|42: icon = icon or MessageBoxIcon.Information|61: MessageBox.Show(caption,arg[0],MessageBoxButtons.OK,icon)|3:end|0:|28:function ShowError (caption)|48: ShowMessageBox(caption,MessageBoxIcon.Error)|3:end|0:|62:---------- Utility function for creating classes -------------|44:--- Does single-inheritance and _delegation_|20:function class(base)|94: local c = {} -- a new class instance, which is the metatable for all objects of this type|54: local mt = {} -- a metatable for the class instance|20: local userdata_base|20: if base == nil then|7: --nada|34: elseif type(base) == 'table' then|55: -- our new class is a shallow copy of the base class!|27: for i,v in pairs(base) do|11: c[i] = v|5: end|16: c._base = base|48: -- inherit the 'not found' handler, if present|48: if c._handler then mt.__index = c._handler end|4: end|56: -- the class will be the metatable for all its objects,|46: -- and they will look up their methods in it.|14: c.__index = c|0:|60: -- expose a ctor which can be called by <classname>(<args>)|36: mt.__call = function(class_tbl,...)|15: local obj= {}|21: setmetatable(obj,c)|94: -- nice alias for the base class ctor (which you have to call explicitly if you have a ctor)|39: if base then c.super = base._init end|17: if c._init then|19: c._init(obj,...)|6: else|66: -- make sure that any stuff from the base class is initialized!|30: if base and base._init then|23: base._init(obj,...)|6: end|5: end|12: return obj|4: end|0:|84: -- Call Class.catch to set a handler for methods/properties not found in the class!|28: c.catch = function(handler)|22: c._handler = handler|22: mt.__index = handler|4: end|15: c._init = ctor|30: c.is_a = function(self,klass)|30: local m = getmetatable(self)|55: if not m then return false end --*can't be an object!|12: while m do|37: if m == klass then return true end|24: m = rawget(m,'_base')|5: end|14: return false|4: end|27: c.class_of = function(obj)|22: return c.is_a(obj,c)|4: end|86: -- any object can have a specified delegate which is called with unrecognized methods|67: -- if _handler exists and obj[key] is nil, then pass onto handler!|32: c.delegate = function(self,obj)|23: local me = self|32: mt.__index = function(tbl,key)|31: -- handling fields!|48: local getter = rawget(c,"Get_"..key)|48: if getter then return getter(me) end|40: getter = rawget(me,"_"..key)|44: if getter then return getter end|26: local method = obj[key]|17: if method then|62: -- it exists in the delegate! First check if it's callable|69: if type(method) == 'function' or getmetatable(method).__call then|30: return function(self,...)|28: return method(obj,...)|8: end|34: else -- otherwise, just return|18: return method|7: end|28: elseif self._handler then|33: return self._handler(tbl,key)|6: end|5: end|39: c.__newindex = function(self,key,val)|48: local setter = rawget(c,"Set_"..key)|26: if setter then|32: setter(self,val)|16: else|30: obj[key] = val|15: end|5: end|4: end|19: setmetatable(c,mt)|9: return c|3:end|0:|56:----------- Creating Menus -----------------------------|0:|42:local ShortcutType = Shortcut.F1:GetType()|0:|33:local function parse_shortcut (s)|13: local res|59: if pcall(function() -- we have to catch the exception!|46: res = Enum.Parse(ShortcutType,s,false)|28: end) then return res end|3:end|0:|40:local function add_menu_items (item,tbl)|23: for i = 1,#tbl,2 do|61: item.MenuItems:Add(create_menu_item(tbl[i],tbl[i+1]))|7: end|3:end|0:|40:function create_menu_item (label,action)|27: local item = MenuItem()|45: local shortcut = label:match('%((%w+)%)')|20: if shortcut then|49: local shortcut = parse_shortcut(shortcut)|53: if shortcut then item.Shortcut = shortcut end|37: label = label:match('(.+)%(')|7: end|21: item.Text = label|38: if type(action) == 'function' then|30: item.Click:Add(action)|8: else|35: add_menu_items(item,action)|7: end|15: return item|3:end|0:|24:function main_menu (tbl)|25: local mm = MainMenu()|26: add_menu_items(mm,tbl)|13: return mm|3:end|0:|25:function popup_menu (tbl)|28: local mm = ContextMenu()|26: add_menu_items(mm,tbl)|13: return mm|3:end|0:|78:-- a useful function for creating menu callbacks to methods of a given object.|25:function method (obj,fun)|21: return function()|10: fun(obj)|4: end|3:end|0:|42:local function populate_control (form,tbl)|14: set(form,tbl)|59: if #tbl > 0 then -- has an array part, containing controls|19: if #tbl == 1 then|29: table.insert(tbl,1,"Fill")|5: end|13: local i = 1|20: while i <= #tbl do|19: local c = tbl[i]|13: local dock|30: if type(c) == 'string' then|12: dock = c|16: c = tbl[i+1]|13: i = i + 1|28: c.Dock = DockStyle[dock]|6: end|23: form.Controls:Add(c)|12: i = i + 1|5: end|4: end|15: return form|3:end|0:|22:function LuaForm (tbl)|36: return populate_control(Form(),tbl)|3:end|0:|23:function LuaPanel (tbl)|37: return populate_control(Panel(),tbl)|3:end|0:|0:|45:---------------- Stream Layout --------------|22:StreamLayout = class()|0:|34:function StreamLayout:_init(panel)|18: self.xsep = 10|19: self.X = self.xsep|19: self.Y = self.xsep|19: self.panel = panel|20: self.newline = true|14: self.maxX = 0|19: self.maxHeight = 0|17: self.labels = {}|27: self.panel:SuspendLayout()|3:end|0:|33:function StreamLayout:Add(c,like)|39: if like then self.X = like.Left end|34: c.Location = Point(self.X,self.Y)|27: self.panel.Controls:Add(c)|38: self.X = self.X + c.Width + self.xsep|39: self.maxX = math.max(self.maxX,self.X)|51: self.maxHeight = math.max(self.maxHeight,c.Height)|21: if self.newline then|17: self.firstC = c|22: self.newline = false|20: self.maxHeight = 0|4: end|3:end|0:|37:function StreamLayout:AddRow(lbl,...)|18: local row = {...}|15: if lbl then|23: local label = Label()|23: label.AutoSize = true|18: label.Text = lbl|19: row.label = label|25: append(self.labels,row)|17: self:Add(label)|4: end|26: for i,c in ipairs(row) do|13: self:Add(c)|4: end|15: self:NextRow()|3:end|0:|30:function StreamLayout:Height()|43: return self.Y + self.maxHeight + self.xsep|3:end|0:|29:function StreamLayout:Width()|20: return self.maxX|3:end|0:|31:function StreamLayout:NextRow()|26: self.Y = self:Height()|19: self.X = self.xsep|20: self.newline = true|3:end|0:|31:function StreamLayout:Finish ()|19: local width = 0|36: for i,row in ipairs(self.labels) do|41: width = math.max(width,row.label.Width)|4: end|60: if width > 0 then -- i.e there is an explicit row of labels|37: for i,row in ipairs(self.labels) do|24: local lbl = row.label|28: for j,c in ipairs(row) do|41: c.Left = c.Left + (width - lbl.Width)|60: self.maxX = math.max(self.maxX,c.Left+c.Width+self.xsep)|6: end|5: end|4: end|31: self.panel:ResumeLayout(false)|3:end|0:|20:LayoutForm = class()|0:|28:function LayoutForm:_init ()|19: self.form = Form()|38: self.layout = StreamLayout(self.form)|24: self.hasButtons = false|16: self.ok = false|20: self.cancel = false|28: self.finishedLayout = false|68: -- this method can only be called once we've set up our own fields!|25: self:delegate(self.form)|51: self.FormBorderStyle = FormBorderStyle.FixedDialog|25: self.MaximizeBox = false|25: self.MinimizeBox = false|3:end|0:|33:function LayoutForm:AddControl(c)|22: self.layout:Add(c)|3:end|0:|42:function LayoutForm:AddControlRow(lbl,...)|31: self.layout:AddRow(lbl,...)|3:end|0:|38:function LayoutForm:AddTextBoxRow(lbl)|26: local textBox = TextBox()|32: self:AddControlRow(lbl,textBox)|15: return textBox|3:end|0:|35:function LayoutForm:Btn (title,res)|22: local b = Button()|15: b.Text = title|31: if res == DialogResult.OK then|23: self.AcceptButton = b|39: elseif res == DialogResult.Cancel then|23: self.CancelButton = b|4: end|19: self.layout:Add(b)|23: self.hasButtons = true|9: return b|3:end|0:|33:function LayoutForm:OkBtn (title)|42: return self:Btn(title,DialogResult.OK)|3:end|0:|37:function LayoutForm:CancelBtn (title)|46: return self:Btn(title,DialogResult.Cancel)|3:end|0:|29:function LayoutForm:NextRow()|25: self.layout:NextRow()|3:end|0:|31:function LayoutForm:OkCancel ()|51: if not self.layout.newline then self:NextRow() end|26: self.ok = self:OkBtn "OK"|38: self.cancel = self:CancelBtn "Cancel"|3:end|0:|26:function LayoutForm:OnOK()|12: return true|3:end|0:|40:function LayoutForm:CenterControls (...)|15: local w = 0|20: local ctrls = {...}|28: for _,c in ipairs(ctrls) do|20: w = w + c.Width|4: end|52: local diff = (self.layout:Width() - w)/(#ctrls + 1)|16: local xx = diff|28: for _,c in ipairs(ctrls) do|16: c.Left = xx|26: xx = xx + c.Width + diff|4: end|3:end|0:|34:function LayoutForm:FinishLayout()|31: if not self.hasButtons then|17: self:OkCancel()|42: self:CenterControls(self.ok,self.cancel)|30: self.ok.Click:Add(function()|22: if self:OnOK() then|39: self.DialogResult = DialogResult.OK|7: else|41: self.DialogResult = DialogResult.None|6: end|6: end)|4: end|27: local layout = self.layout|16: layout:Finish()|56: self.ClientSize = Size(layout:Width(), layout:Height())|27: self.finishedLayout = true|3:end|0:|35:function LayoutForm:ShowDialogOK ()|35: if not self.finishedLayout then|21: self:FinishLayout()|4: end|44: return self:ShowDialog() == DialogResult.OK|3:end|0:|61:------------------- Converters ------------------------------|96:-- These classes convert values between controls and Lua values, and provide basic verification,|63:-- like ensuring that a string is a valid number, for instance.|72:-- They provide an appropriate control for editing the particular value.|19:Converter = class()|0:|29:function Converter:Control ()|24: self.box = TextBox()|16: return self.box|3:end|0:|27:function Converter:Read (c)|17: return c.Text|3:end|0:|33:function Converter:Write (c,text)|17: c.Text = text|3:end|0:|34:NumberConverter = class(Converter)|0:|33:function NumberConverter:Read (c)|19: local txt = c.Text|31: local value = tonumber(txt)|75: if not value then return nil, "Cannot convert '"..txt.."' to a number" end|13: return value|3:end|0:|32:BoolConverter = class(Converter)|0:|33:function BoolConverter:Control ()|21: return CheckBox()|3:end|0:|31:function BoolConverter:Read (c)|20: return c.Checked|3:end|0:|36:function BoolConverter:Write (c,val)|19: c.Checked = val|3:end|0:|32:ListConverter = class(Converter)|0:|35:function ListConverter:_init (list)|20: self.list = list|3:end|0:|33:function ListConverter:Control ()|21: local c = ComboBox()|31: if not self.list.Editable then|46: c.DropDownStyle = ComboBoxStyle.DropDownList|4: end|35: for i,item in ipairs(self.list) do|19: c.Items:Add(item)|4: end|9: return c|3:end|0:|31:function ListConverter:Read (c)|30: local val = c.SelectedItem|33: if not val then val = c.Text end|11: return val|3:end|0:|36:function ListConverter:Write (c,val)|24: c.SelectedItem = val|3:end|0:|32:FileConverter = class(Converter)|0:|43:function FileConverter:_init (reading,mask)|79: -- the filter is in a simplified form like 'Lua Files (*.lua)|C# Files (*.cs)"|47: -- this will expand it into the required form.|52: self.filter = mask:gsub("%((.-)%)",function(pat)|28: return "("..pat..")|"..pat|5: end)|23: self.reading = reading|3:end|0:|95:-- ExtraControl is an optional method which gives a converter the opportunity of adding another|95:-- control to the row after the primary control. In this case, we create a file browser button.|38:function FileConverter:ExtraControl ()|24: local btn = Button()|21: local box = self.box|15: btn.Width = 30|16: btn.Text = ".."|25: btn.Click:Add(function()|77: -- if possible, open the file browser in the same directory as the filename|29: local path = self:Read(box)|31: if not File.Exists(path) then|41: path = Directory.GetCurrentDirectory()|6: else|37: path = Path.GetDirectoryName(path)|5: end|92: -- depending on whether we want a file to read or write ("Save as"), pick the file dialog.|15: local filebox|47: if self.reading then filebox = OpenFileDialog|36: else filebox = SaveFileDialog end|23: local dlg = filebox()|26: dlg.Filter = self.filter|29: dlg.InitialDirectory = path|45: if dlg:ShowDialog() == DialogResult.OK then|31: self:Write(box,dlg.FileName)|5: end|5: end)|11: return btn|3:end|0:|100:-- Note an important convention: this converter puts the full file path in the text box's Tag field,|0:|36:function FileConverter:Write (c,val)|34: c.Text = Path.GetFileName(val)|12: c.Tag = val|3:end|0:|31:function FileConverter:Read (c)|16: return c.Tag|3:end|0:|94:-- there are then two subclasses, depending if you want to open a file for reading or writing.|0:|29:FileIn = class(FileConverter)|0:|28:function FileIn:_init (mask)|25: self:super(true,mask)|3:end|0:|30:FileOut = class(FileConverter)|0:|29:function FileOut:_init (mask)|26: self:super(false,mask)|3:end|0:|20:local converters = {|28: number = NumberConverter(),|22: string = Converter(),|27: boolean = BoolConverter(),|1:}|0:|47:function Converter.AddConverter (typename,conv)|31: converters[typename] = conv|3:end|0:|61:---------------- AutoVarDialog ------------------------------|0:|32:local function callable (method)|32: local mt = getmetatable(method)|56: return type(method) == 'function' or (mt and mt.__call)|3:end|0:|32:local function simple_list (nxt)|44: return type(nxt) == 'table' and #nxt > 0|3:end|0:|33:AutoVarDialog = class(LayoutForm)|0:|34:function AutoVarDialog:_init (tbl)|15: self.rows = {}|26: self.T = tbl.Object or _G|25: self.verify = tbl.Verify|39: self.verify_exists = tbl.Verify ~= nil|55: --end of local fields; NOW we can initialize the form!|17: self.super(self)|35: self.Text = tbl.Text or "untitled"|19: local i,n = 1,#tbl|19: while i <= n do|34: local converter,constraint,extra|20: local lbl = tbl[i]|22: local var = tbl[i+1]|27: local value = self.T[var]|27: local vtype = type(value)|53: -- is there a particular default or constraint set?|17: if i+1 < n then|23: local nxt = tbl[i+2]|32: if type(nxt) ~= 'string' then|25: if callable(nxt) then|21: constraint = nxt|32: elseif simple_list(nxt) then|49: -- have been given a list of possible values|35: converter = ListConverter(nxt)|39: elseif Converter.class_of(nxt) then|20: converter = nxt|8: else|61: ShowError("Unknown converter or verify function: "..nxt)|11: return|7: end|13: i = i + 1|6: end|5: end|23: if not converter then|54: -- use a default converter appropriate to this type|32: converter = converters[vtype]|24: if not converter then|58: ShowError("Cannot find a converter for type: "..vtype)|10: return|6: end|5: end|31: local c = converter:Control()|82: self:AddControlRow(lbl,c,converter.ExtraControl and converter:ExtraControl())|26: converter:Write(c,value)|80: append(self.rows,{cntrl=c,converter=converter,var=var, constraint=constraint})|11: i = i + 2|4: end|3:end|0:|30:function AutoVarDialog:OnOK ()|13: local T = {}|35: for _,t in ipairs(self.rows) do|45: local value,err = t.converter:Read(t.cntrl)|34: if not err and t.constraint then|28: err = t.constraint(value)|5: end|13: if err then|17: ShowError(err)|18: t.cntrl:Focus()|15: return false|5: end|18: T[t.var] = value|4: end|54: -- a function to verify the fields has been supplied|27: if self.verify_exists then|28: local err = self.verify(T)|13: if err then|17: ShowError(err)|15: return false|5: end|4: end|69: -- NOW we can finally copy the changed values into the target table!|23: for k,v in pairs(T) do|18: self.T[k] = v|4: end|15: return true|3:end|0:|24:function Match (pat,err)|23: return function (s)|34: --ferr:write(',',s,',',pat,'\n')|40: if not s:find(pat) then return err end|4: end|3:end|0:|22:function Range (x1,x2)|38: if not x2 then -- unbound upper range|20: return function(x)|56: if x < x1 then return "Must be greater than "..x1 end|5: end|42: elseif not x1 then -- unbound lower range|20: return function(x)|53: if x > x2 then return "Must be less than "..x2 end|5: end|5: else|20: return function(x)|74: if x < x1 or x > x2 then return "Must be in range "..x1.." to "..x2 end|5: end|4: end|3:end|0:|53:NonBlank = Match ('%S+','Must be a non-blank string')|38:Word = Match('^%w+$','Must be a word')|0:|62:--- A useful function for prompting a user for a single value.|71:-- returns a non-nil value if the user clicks on OK or presses <enter>.|49:function PromptForString (caption,prompt,default)|34: local tbl = {val = default or ""}|61: local form = AutoVarDialog {Text = caption, Object = tbl;|14: prompt,"val"|2: }|28: if form:ShowDialogOK() then|16: return tbl.val|4: end|3:end|0:|
Codepage=16
Styles=#17:// Язык подсветки|14:@1 Language=15|0:|73:// Настройка стиля синтаксиса подсветки в соответствии с выбранным языком|98:// 1-синтаксическая инструкция, стили шрифта 2-полужирный, 3-курсив, 4-подчёркнутый, 5-цвет шрифта|83:# LUA_DEFAULT=0, FontBold=False, FontItalic=False, FontUnderline=False, FontColor=0|87:# LUA_COMMENT=1, FontBold=False, FontItalic=True, FontUnderline=False, FontColor=39680|91:# LUA_COMMENTLINE=2, FontBold=False, FontItalic=True, FontUnderline=False, FontColor=39680|90:# LUA_COMMENTDOC=3, FontBold=False, FontItalic=True, FontUnderline=False, FontColor=39680|84:# LUA_NUMBER=4, FontBold=False, FontItalic=False, FontUnderline=False, FontColor=255|86:# LUA_WORD=5, FontBold=True, FontItalic=False, FontUnderline=False, FontColor=8323072|89:# LUA_STRING=6, FontBold=False, FontItalic=False, FontUnderline=False, FontColor=11633048|91:# LUA_CHARACTER=7, FontBold=False, FontItalic=False, FontUnderline=False, FontColor=8323252|93:# LUA_LITERALSTRING=8, FontBold=False, FontItalic=False, FontUnderline=False, FontColor=27871|90:# LUA_PREPROCESSOR=9, FontBold=False, FontItalic=False, FontUnderline=False, FontColor=255|92:# LUA_OPERATOR=10, FontBold=False, FontItalic=False, FontUnderline=False, FontColor=11534336|87:# LUA_IDENTIFIER=11, FontBold=False, FontItalic=False, FontUnderline=False, FontColor=0|88:# LUA_STRINGEOL=12, FontBold=False, FontItalic=False, FontUnderline=False, FontColor=255|88:# LUA_WORD2=13, FontBold=False, FontItalic=False, FontUnderline=False, FontColor=8323072|87:# LUA_WORD3=14, FontBold=False, FontItalic=True, FontUnderline=False, FontColor=8323072|88:# LUA_WORD4=15, FontBold=False, FontItalic=False, FontUnderline=False, FontColor=8355584|84:# LUA_LABEL=20, FontBold=False, FontItalic=False, FontUnderline=False, FontColor=255|0:|
WordsKey1=#106:and break do else elseif end false for function if in local nil not or repeat return then true until while|
WordsKey2=#128:_VERSION assert collectgarbage dofile error gcinfo loadfile loadstring print rawget rawset require tonumber tostring type unpack|
WordsKey3=#60:string.byte string.char string.dump string.find string.len \|88:string.lower string.rep string.sub string.upper string.format string.gfind string.gsub \|102:table.concat table.foreach table.foreachi table.getn table.sort table.insert table.remove table.setn \|88:math.abs math.acos math.asin math.atan math.atan2 math.ceil math.cos math.deg math.exp \|81:math.floor math.frexp math.ldexp math.log math.log10 math.max math.min math.mod \|83:math.pi math.pow math.rad math.random math.randomseed math.sin math.sqrt math.tan \|54:string.gmatch string.match string.reverse table.maxn \|59:math.cosh math.fmod math.modf math.sinh math.tanh math.huge|
WordsKey4=#43:abs acos asin atan atan2 ceil cos deg exp \|75:floor format frexp gsub ldexp log log10 max min mod rad random randomseed \|75:sin sqrt strbyte strchar strfind strlen strlower strrep strsub strupper tan|
BraceBadBold=1
ColorIGFore=9413297
ColorOfFlags=12639424
NumSizeCorrect=-1
MarginNumFore=8421504
Markers=1
MarkMarginWidth=14
MarkerForm=8
Fold=1
FoldMarginWidth=14
FoldMarginColor1=13424089
FoldIcon=1
AutoComplete=1
AutoCompStrings=#106:and break do else elseif end false for function if in local nil not or repeat return then true until while|0:|
MinWordLen=2
ScrollBars=2
Point(LinePosition)
Point(ArrayFold)
Point(Position)
}
карма: 6

0
Редактировалось 11 раз(а), последний 2017-12-01 16:15:53