Lua Newb Question

724 views
Skip to first unread message

Dinsdale

unread,
Aug 18, 2011, 6:51:20 PM8/18/11
to scite-interest
Hey there, I've been using scite for quite a while now, but have just
finally gotten around to using some of the more advanced features now.
Better late than never...

Anyway, I wanted to start using lua to do some simple extensions, such
as count all the letters and words. I have been following these two
sites for instruction:

http://lua-users.org/wiki/UsingLuaWithScite -- basic instruction

http://www.rrreese.com/Article/Show/SciteWordCount -- word count
functionality

I am using Windows 7 and I got the most basic example working, but
when I try to load a separate file, it fails with the following
message:

>WordCount
>The system cannot find the file specified.

I decide to simplify it and did the following:

1)
#From example 1
command.name.1.*=Run Document as Lua Extension
command.1.*=dostring dostring(editor:GetText())
command.subsystem.1.*=3
command.mode.1.*=savebefore:no

#first attempt
#ext.lua.startup.script=$(SciteUserHome)/wordcount.lua
#command.name.2.*=Count Words
#command.2.*=WordCount
#command.2.subsystem.*=3
#command.mode.2.*=savebefore:no

#Current attempt
ext.lua.startup.script=$(SciteUserHome)/dostuff.lua
command.name.2.*=Do Stuff
command.2.*=DoStuff
command.2.subsystem.*=3
command.mode.2.*=savebefore:no


2) created the dostuff.lua file in my "home" directory with the
following function:

function DoStuff()
print("This is a do stuff function");
end

I have double checked my home directory by running the following
(using the ctrl+1 function in my properties file above):

print(props['SciteUserHome']);

and it returns correctly. but I still get the file not found error:

>DoStuff
>The system cannot find the file specified.

I know this is basic basic stuff, but I've spent hours trying to get
it going. Could someone please tell me what the heck I'm doing wrong?
I tried searching this group but apparently my problem is SO basic and
obvious that it's not here. I know, I suck. :(

Thanks in advance!
dinsdale

KHMan

unread,
Aug 19, 2011, 6:23:37 AM8/19/11
to scite-i...@googlegroups.com
On 8/19/2011 6:51 AM, Dinsdale wrote:
> [snip]

> I have double checked my home directory by running the following
> (using the ctrl+1 function in my properties file above):
>
> print(props['SciteUserHome']);
>
> and it returns correctly. but I still get the file not found error:
>
>> DoStuff
>> The system cannot find the file specified.
>
> I know this is basic basic stuff, but I've spent hours trying to get
> it going. Could someone please tell me what the heck I'm doing wrong?
> I tried searching this group but apparently my problem is SO basic and
> obvious that it's not here. I know, I suck. :(

Yep, everything looks correct, but I'm on XP and I think it's best
if someone on Win7/Vista chime in. What I'm afraid of is the new
virtualized directories thingy for user settings...

One option to try is to set a SciteUserHome environment variable
and see if it's any different...

--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia

bfisher

unread,
Aug 19, 2011, 3:31:55 PM8/19/11
to scite-interest

On Aug 19, 3:23 am, KHMan <keinh...@gmail.com> wrote:
> On 8/19/2011 6:51 AM, Dinsdale wrote:
> > and it returns correctly. but I still get the file not found error:
>
> >> DoStuff
> >> The system cannot find the file specified.
>
> Yep, everything looks correct, but I'm on XP and I think it's best
> if someone on Win7/Vista chime in. What I'm afraid of is the new
> virtualized directories thingy for user settings...
>

Glad you're experimenting with customizing Scite, I've found it to be
a good investment.
What you have described works for me on Win7.
A few things to try:
Place a print statement in your lua startup script (outside of the
function). If you see that statement when you start scite, then it's
actually running the startup script.
If not, try using a fully qualified path, like C:\Users\befisher
\startup.lua

It's odd that you are seeing the error
>> The system cannot find the file specified.
If I put gibberish in the command.2.*, I get
> Lua: error checking global scope for command

When I am using Lua, I don't generally use a startup script, and
instead run the files separately, like:
command.name.2.*=Test2
command.2.*=dofile $(SciteHome)\scripts\myscript.lua
command.subsystem.2.*=3
command.mode.2.*=savebefore:no

-Ben




Dinsdale

unread,
Aug 19, 2011, 8:32:12 PM8/19/11
to scite-interest
I've tried the fully qualified path, with both style slashes. However,
your suggestion of putting a print statement before the function
worked.
properties file:
ext.lua.startup.script=$(SciteUserHome)\dostuff.lua
command.name.2.*=Do Stuff
command.2.*=dostuff
command.2.subsystem.*=3
command.mode.2.*=savebefore:no

dostuff.lua file

print("This is a do stuff function");

function dostuff()
print("This is a do stuff function");

end

When I start scite, I get "This is a do stuff function", but then I
try to run the function and I get the same error:

">dostuff"
">The system cannot find the file specified."

I modified my prop file like you suggested:

command.name.2.*=Do Stuff
command.2.*=$(SciteUserHome)\dostuff.lua
command.2.subsystem.*=3
command.mode.2.*=savebefore:no

and I get a different error
">C:\Users\<randomuserhome>\dostuff.lua"
">%1 is not a valid Win32 application."

So it does seem to be some issue with my function call... maybe?

I forgot how frustrating learning a new language can be.

Thanks!
dinsdale

KHMan

unread,
Aug 19, 2011, 10:56:27 PM8/19/11
to scite-i...@googlegroups.com
On 8/20/2011 8:32 AM, Dinsdale wrote:
> I've tried the fully qualified path, with both style slashes. However,
> your suggestion of putting a print statement before the function
> worked.
> properties file:
> ext.lua.startup.script=$(SciteUserHome)\dostuff.lua
> command.name.2.*=Do Stuff
> command.2.*=dostuff
> command.2.subsystem.*=3
> command.mode.2.*=savebefore:no

This entry should then appear in the Tool menu, and you can start
it from there. For frequently used scripts, use Ctrl-1 to Ctrl-9.
Other key combinations can also be used, I think the SciteLua wiki
covers it.

> [snip]


> When I start scite, I get "This is a do stuff function", but then I
> try to run the function and I get the same error:
>
> ">dostuff"
> ">The system cannot find the file specified."

You can't run it from any kind of command prompts, AFAIK.

Dinsdale

unread,
Aug 20, 2011, 1:08:22 AM8/20/11
to scite-interest
I'm trying to execute it from within scite, using both ctrl+2 and the
tools menu.

Thanks
Russ

Dinsdale

unread,
Aug 20, 2011, 1:10:22 AM8/20/11
to scite-interest
Just an FYI. The version number from the about screen:

SciTE
Version 2.20
Jul 30 2010 16:04:18
by Neil Hodgson.
December 1998-July 2010.
http://www.scintilla.org
Lua scripting language by TeCGraf, PUC-Rio
http://www.lua.org

On Aug 19, 9:56 pm, KHMan <keinh...@gmail.com> wrote:

KHMan

unread,
Aug 20, 2011, 1:20:22 AM8/20/11
to scite-i...@googlegroups.com
On 8/20/2011 1:08 PM, Dinsdale wrote:
> I'm trying to execute it from within scite, using both ctrl+2 and the
> tools menu.

Okay, my mistake, I got confused... appeared that it tried to run
'dostuff' as an application instead of passing it to the Lua
extension. Which is a useful bit of information.

Aha, looking very closely, I noticed this has the wrong format:

command.subsystem.number.filepattern

You need to fix that line :-)

> On Aug 19, 9:56 pm, KHMan wrote:
>> On 8/20/2011 8:32 AM, Dinsdale wrote:
>>
>>> I've tried the fully qualified path, with both style slashes. However,
>>> your suggestion of putting a print statement before the function
>>> worked.
>>> properties file:
>>> ext.lua.startup.script=$(SciteUserHome)\dostuff.lua
>>> command.name.2.*=Do Stuff
>>> command.2.*=dostuff
>>> command.2.subsystem.*=3
>>> command.mode.2.*=savebefore:no
>>

[snip snip]

Philippe Lhoste

unread,
Aug 20, 2011, 5:08:43 AM8/20/11
to scite-i...@googlegroups.com
On 20/08/2011 02:32, Dinsdale wrote:
> I've tried the fully qualified path, with both style slashes. However,
> your suggestion of putting a print statement before the function
> worked.
> properties file:
> ext.lua.startup.script=$(SciteUserHome)\dostuff.lua
> command.name.2.*=Do Stuff
> command.2.*=dostuff
> command.2.subsystem.*=3
> command.mode.2.*=savebefore:no

You can use command.mode to get rid of subsystem line:
command.mode.4.*=subsystem:lua,savebefore:no

Better stick to forward slash, anyway.

> dostuff.lua file
>
> print("This is a do stuff function");
>
> function dostuff()
> print("This is a do stuff function");
>
> end
>
> When I start scite, I get "This is a do stuff function", but then I
> try to run the function and I get the same error:
>
> ">dostuff"
> ">The system cannot find the file specified."

Here, it is strange, as obviously it finds the file on startup.
Moreover, you shouldn't have the >dostuff line in the output.
When I run a Lua function, I only get the result of print() (or changes
to the buffer). It looks like it tries to use subsystem 2 instead of 3.
Perhaps you should try and use different names for the function and for
the file, just to sort things out.

> I modified my prop file like you suggested:
>
> command.name.2.*=Do Stuff
> command.2.*=$(SciteUserHome)\dostuff.lua
> command.2.subsystem.*=3
> command.mode.2.*=savebefore:no
>
> and I get a different error
> ">C:\Users\<randomuserhome>\dostuff.lua"
> ">%1 is not a valid Win32 application."
>
> So it does seem to be some issue with my function call... maybe?

Again, confusion of 2 and 3.

Suggestion, just in case: upgrade to the latest version of SciTE. It
cannot hurt...

--
Philippe Lhoste
-- (near) Paris -- France
-- http://Phi.Lho.free.fr
-- -- -- -- -- -- -- -- -- -- -- -- -- --

Dinsdale

unread,
Aug 20, 2011, 11:07:47 PM8/20/11
to scite-interest
That was it! Thank you so much KHMan! I changed the subsystem line and
it worked right away.

And thank you everyone else for helping me with this! I'm glad to see
that there is a supportive community here. Keep up the great work
everyone.

Cheers
Dinsdale
Reply all
Reply to author
Forward
0 new messages