Brian Sanders | 8 Oct 04:25

New to LUA, trying to read from a file

Hello,  I am new to LUA and was trying to do some basic scripts to get a feel for it.  I have tried to make a basic script to parse through a log file and display simple output.  I have the following code which I thought I understood just fine.

print ("opening file for reading")
logfile = io.open("system.log","r")
logstring = logfile:read("*all")
print(logstring)

What is confusing me is, I can create a new text document, and just type a few words in it.  Then I can use this script (unless in my many variations I posted the wrong one) and get the text back out.  If I could get past this, I would then do some small matching off the log file.  Unfortunately it only works when I make my text document.  When I grab the actual log file I am trying to parse, it only returns a space, a square, and then the first character in the file.  When opening this log file in word pad it does look normal with line returns after each log entry.  In notepad however the line returns are shown as squares.  I am therefore led to believe this must have something to do with formatting of this file, but I really don't know.  Can anyone point me in the right direction here?  I just don't see how these line returns could be the problem when it does not even parse that far, it just gets to the first character.

Thanks for helping a new guy out,
Brian



--
"Faithless is he, who says 'farewell', when the path darkens
"you just keep on trying till you run out of cake"
Ralph Hempel | 7 Oct 17:06

Cygwin Target in Lua makefile

Is there any desire (or benefit) to having a Cygwin target in
the main Lua makefiles?

There are just enough differences between Cygwin, linux, generic
and mingw to make it seem worthwhile...

Ralph

A.S. Bradbury | 5 Oct 20:48

[ANN] lua-discount 1.2.10.1

I'm pleased to announce the release of lua-discount 1.2.10.1. This
release offers Windows support thanks to contributions from Tim
Channon. Thanks to Hisham Muhammad for getting a win32-x86 binary rock
into the repository. Anyone running on Mac, Linux or Windows should be
able to install lua-discount by typing `luarocks install
lua-discount`.

# lua-discount

A binding to [Discount](http://www.pell.portland.or.us/~orc/Code/discount/), a
fast C implementation of the
[Markdown](http://daringfireball.net/projects/markdown) text to HTML markup
system. Discount passes the Markdown test suite.

## Project links
* [Home](http://asbradbury.org/projects/lua-discount/)
* [Download](http://luaforge.net/projects/lua-discount/)
* [Documentation](http://asbradbury.org/projects/lua-discount/#usage)
* [Source](http://github.com/asb/lua-discount/)

## Release history
* lua-discount-1.2.10.1 (2008-09-22)
  * Windows is now a supported platform (thanks to contributions from Tim
    Channon)
* lua-discount-1.2.10 (2008-09-03)
  * update to upstream Discount 1.2.10
  * support the `"nohtml"` option, to disable embedded html.
  * compile to use relaxed emphasis, meaning underscores don't count when
    they're in the middle of a word.
  * add some tests
  * include results of a simple benchmark in the readme
* lua-discount-1.2.7 (2008-08-03)
  * first public release

## See also
* [Discount](http://www.pell.portland.or.us/~orc/Code/discount/)
* [Markdown syntax](http://daringfireball.net/projects/markdown/syntax)
* [markdown.lua](http://www.frykholm.se/files/markdown.lua)

## Performance
Thanks to the underlying Discount implementation, lua-discount is incredibly
fast. Benchmarking markdown.lua 0.32 against lua-discount 1.2.10 by parsing
the [Markdown syntax
document](http://daringfireball.net/projects/markdown/syntax.text) 100 times
gives the following result (all figures are in seconds):

                       user     system      total       real
    lua-discount   0.170000   0.000000   0.170000   0.177374
    markdown.lua  48.530000   0.000000  48.530000  48.524910

## [Usage](id:usage)
Note that `require("discount")` returns a single function, which you are
responsible for giving a suitable name. Example:

    discount = require("discount")

    local markdown_string = [[
      # Demonstration
      This is a demonstration of lua-discount. Passing the options `"nolinks"`
      disables links such as [this](http://example.com).
      ]]

      local html_string = discount(markdown_string, "nolinks")

The `discount` function takes as its first argument the Markdown string to
convert, and for its subsequent arguments takes any combination of the
following strings as options:

=`"nolinks"`=
    do not allow `<a` or expand Markdown links.
=`"noimages"`=
    do not allow `<img` or expand Markdown images.
=`"nopants"`=
    disable [SmartyPants](http://daringfireball.net/projects/smartypants/)
    processing.
=`"nohtml"`=
    disallow embedded html by replacing all `<` with `&lt;`.
=`"tagtext"`=
    don't expand `*` or `_` when used for emphasis.
=`"noext"`=
    do not process
    [pseudo-protocols](http://www.pell.portland.or.us/~orc/Code/discount/#pseudo)
=`"cdata"`=
    generate output suitable for use as data in an XML document.
= `"embed"`=
    equivalent to specifying `"nolinks"`, `"noimages"` and `"tagtext"`.

## License and acknowledgements
lua-discount is distributed under [a BSD-style
license](http://github.com/asb/lua-discount/tree/master/LICENSE).

Thanks to Tim Channon for Windows support.

This product includes software developed by [David Loren
Parsons](http://www.pell.portland.or.us/~orc).

## Contact
Author: A.S. Bradbury
Email: <asb <at> asbradbury.org>
Homepage: <http://asbradbury.org/>

Ready to use Kepler no Apache through Uniform server.

I had been looking for a way to have Lua on Apache Web Server. Today I came
across the Kepler plugin of the Uniform Server (WAMP package).
I haven't given it a try yet but I was excited to find out there is a way to get
a ready made, no fuss, just run, preconifgured package for development.

Have a look:
http://bananaacid.kicks-ass.net/?kepler

Gavin Wraith | 5 Oct 13:54

SciTE, GUIs, desktop real estate

I apologize if this is the wrong forum for this post - it should
be the SciTE interest group, but that involves joining a Google
group, something that I have so far managed to avoid.

As a dedicated Lua user, and as a newcomer to Windows XP, I have been
delighted by SciTE, especially its configurability by Lua scripts.
But the Windows version has a fundamental drawback (I do not know
if versions on other platforms suffer the same): you can only view
one file at a time. I say "view", not "open". The whole purpose of a
desktop GUI is to be able to read information from various sources
simultaneously. I do not want to obscure the window in which I am
writing when I am consulting information in other windows; I need
to see all of them, at once. Lots of text-editors for Windows seem
to deny the purpose of a desktop in this way. Why is this?

Another gripe is the hypertrophied toolbar which takes up valuable screen
real estate. Maybe this can be configured, so that all the Lua-debugging
tools only appear when I want them? As tiny notebooks and handheld
computers become more popular, screen real-estate, and its sensible
economic use according to the wishes of the user, will become more
precious. Perhaps we might even get away from the jumbo-jet-cockpit
syndrome that seems to afflict most Windows applications? Less is more.

--

-- 
Gavin Wraith (gavin <at> wra1th.plus.com)
Home page: http://www.wra1th.plus.com/

David Burgess | 5 Oct 04:27

luaforge

It is down

Fabio Mascarenhas | 3 Oct 17:20

Re: JavaScript to Lua compiler

On Fri, Oct 3, 2008 at 11:07 AM, David Jones <drj <at> ravenbrook.com> wrote:
>>
>> Mapping Lua's lexical scope into JavaScript's function scope is easy,
>> rename the variables so the scopes don't clash, and fix the
>> references. It's even easier if you are compiling to a newer
>> JavaScript implementation and use let instead of var.
>
> As you discovered, the poster wanted the other way around.  But...
>
> Your proposal is easy, but it won't get closures correct.  Not even close.
>
> Consider: a={} for i=1,10 do a[i]=function()i=i+1;return i;end end
>
> It's a bit of annoying impedance match either way around.

Yeah, I should have payed more attention to my original answer, thanks
for pointing out my mistake! Alas, this makes implementing Lua in JS
even closer to implementing Lua on the JVM and CLR (which don't have
closures at all), and the implementation would be similar (having
cells to hold upvalues; been there, done that), at least for upvalues
inside loops. Good thing JS now has proper block scoping (thoug not
IE's JS, yet)!

A cleaner way is to compile all Lua loops to JavaScript functions (so
Lua's block scope becomes JS function scope). The function would have
the loop inside it (no tail-recursion, which is a whole other can of
worms :-) ).

Erik Meijer has a similar exaple of this problem in
http://research.microsoft.com/~emeijer/Blog/LookClosure.html, but
comparing C# (which has closures with proper block scoping, as Lua)
with JS. C#'s closure implementation is more complex (using display
classes generated by the compiler) because of C#'s static typing, but
the essence is the same.

For JavaScript to Lua this doesn't matter, though, declaring all vars
in the beginning of the function and preventing name clashes will
implement the correct semantics.

> Cheers,
>  drj
>

--
Fabio Mascarenhas

Evan DeMond | 3 Oct 07:30

Mixing wxLua and LPeg?

Hi all,

I've got a project that runs on the wxLua binary, a big executable with a Lua interpreter statically linked in (to the best of my knowledge.) Now I'd like to mix in LPeg as well, which seems to want to link to its own Lua library (whether dynamically or statically, not sure.) I count two Lua interpreters getting loaded in that setup...

Am I going to have Problems? Any obvious ways around this?

Thanks,

Evan
Xruptor | 2 Oct 17:55

Simple Question

Question: What is a good way to remove all Magic Characters from a string without distorting or breaking the accuracy of the original string?  I figure it has to do with the (%W) pattern.  However all my attempts usually break the string somehow or distort it.  My goal is to remove all possible magic characters from a string before parsing it in a string.find or any other string function.

I'm trying to parse chat information but people are bypassing the string.find function by adding special magic characters to their text strings.  Sometimes it breaks the string and sometimes the parse bypasses all find functions.

This is why I would like to strip all magic characters from a string before parsing ;)  Help is always appreciated.
Tim Channon | 2 Oct 15:09

Unexpected behaviour

Where does argument 3 go?

tagclass = {}
tagmetatable = {__index = tagclass}
function tagclass.new (kind, args, body)
  local self = {}
	self.kind=kind
	self.args=args
	self.body=body
  setmetatable(self,tagmetatable)
  return self
end

function tagclass:show()
	print("kind",self.kind)
	print("args",self.args)
	print("body",self.body)
end

xx=tagclass:new("kindp", "argp", "bodyp")

xx:show()

kind	table: 00887f48
args	kindp
body	argp

Aidin Abedi | 2 Oct 14:35

I need your help! C++ exception in coroutine Crashes.

Hello

I've embedded lua and when I call a c++ function (that throws a c++
exception) inside a coroutine my app crashes badly. Windows just says:

"Runtime Error!
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information."

I do have a c++ exception-catch outside the pcall. There is no crash
if I call the same function (that throws a exception) from inside
lua's main-thread.

This issue must have been detected before. Please help me!
I appreciate any ideas. I thank you for your time.


Gmane