Free Essay

Lua Stuff

In:

Submitted By nixtroid
Words 1294
Pages 6
. Introduction top next

gema actions are enough for everyday usage but occasionally you may need more power to define a complex transformation.

You might, also, want to use the superior matching capabilities of gema to drive your program.

GeL is a Lua 5 library that:

allows the execution of Lua function (and hence of a C function) in a gema action provides the powerful text matching mechanisms offered by gema as a set of Lua functions it has been tested with Lua 5.0.2.

Refer to the detailed documentation to build gel togheter with gema, .

1.1 Status

GeL is not as mature as gema or Lua, please report any bugs you may find using SourceForge bug tracking subsystem (you don't need to log in as a SourceForge user) or sending an e-mail to Remo Dentato.

1.2 Licence

GeL is released under the same licence of Gema. No specific reference needs to be made to GeL as long as the due reference to Gema and Lua have been made.

2. Usage prev top next

2.1 Gema like

Gel may be used exactly as if it was gema, any valid gema script should work when executed by gel:

gel [gemaopts] [-f rules.gema] [-l script.lua] [infile [outfile]]

. The only differences are:

The @lua{} function is available to execute lua scripts in actions Text enclosed between "![" and "!]" is considered lua code and is immediately executed Rules specfied with '-f' are loaded, the lua script specified with '-l' is executed (possibily defining lua function to be used in some gema action) and the infile is translated to the outfile applying the rules defined in the default domain.

All the gema options are recognized. 2.2 Lua like

Gel may be used as a Lua (non interactive) interpreter:

gel [gemaopts] [-f rules.gema] -lua script.lua [args]

Rules specfied with '-f' are loaded then the control is passed to the lua script specified with '-lua'. No input file is opened and it's a script responsability to begin the transformation process.

The optional arguments args are passed to the script in the global table arg:

arg.n will contain the number of arguments; arg[0] will contain the name of the script; arg[x] with x between 1 and arg.n, the arguments. All the gema options are recognized.

2.3 Gua

Gua is a stand-alone Lua interpreter linked against the gel library.

gua [luaopts] [script.lua [args]]

I added gua to this distribution to show how easy is to embed gel functions in your lua enabled programs.

The only difference between gua.c and the original lua.c you can find in the Lua 5.0 distribution, is the addition of the function call gel_init(l) at line 386.
Actually there is another difference that it's not related to gel, I had to add a fflush(stderr) to the l_message() function to fix a problem with the mingw compiler.

2.4 libgel

All the gel function are available as static library named libgel.a on Unix or libgel.lib on Windows. The building process will automatically generate it.

3. Functions prev top next

3.1 Gema

Some new functions havr been added to gema:

@lua{string} that executes string as a piece of lua code. Returns a value only if the lua code explicitly uses return: @lua{f()} returns nothing
@lua{return f()} returns the first value returned by f(). @rules{group}
Reports the status of the nth group of rules. Two new escape sequences ( \Q and \q) have been added to create groups of rules; up to 8 groups can be created numbered from 0 to7.
To understand this new feature, imagine you want to use different rules to parse a block of text. A possible solution is to set a variable and then use @cmpn to have different behaviors with respect to the same match.
Instead, using \Q in a pattern means that that a match should fail if the specified group is disabled. @rules{group;switch}
Modify the status of the nth group: 0: turn off 1: turn on x: toggle @line{mark} the @line function has been extendend to support the \M escape sequence @column{mark} the @column function has been extendend to support the \M escape sequence 3.2 Lua

Lua functions can be loaded in three ways:

using the -l option in the command line; executing @lua{dofile("filename")} in an action; embedding the lua code in the gema rule file between "![" and "!]". The examples in the next section should clarify how to use those three methods.

There are new lua functions to interact with gema environment:

gel.set(varname,value)
Set the value of varname (same as @set{}). gel.get(varname)
Get the value of varname (same as @var{} in gema). Returns nil if the variable is unassigned. gel.push(varname,value)
Use varname as a stack and push a value on top (same as @push{}in gema). gel.pop(varname)
Use varname as a stack and pop the value on top (same as @pop{}in gema). It also returns the popped value. gel.write(string)
Write a string at the current position in the gema output (only works if executed in a function called by gema with @lua{}). gel.parsestring(string,[domain,[output]])
Translate the string using the rules defined into the named domain and write the result to the output file. The output parameter can be the name of a file to be created, or nil meaning that the result should be returned as the value of the function.
If output is "-" the translation will be written in the current gema output.
If domain is "" or nil the default domain will be used. gel.parsefile(file,[domain,[output]])
Same as gel.parsestring but the text to be translated is taken from the specified file. gel.parsestream(stream,[domain,[output]])
Same as gel.parsestring but the text to be translated is taken from the specified stream. gel.streamfile(filename)
Create, from the specified file, a stream to be used with gel.parsestream() gel.streamstring(string)
Create, from the given string, a stream to be used with gel.parsestream() gel.streamclose(stream)
Close the given stream. gel.streameof(stream)
Check if there is some text left in the stream. gel.streamgetc(stream)
Get next char from the stream. gel.streampeek(stream)
Returns te next char from the stream without advancing the stream. gel.rulefile(file)
Read new patterns from the specified file. In gema it would be @define{@read{file}} gel.rulestring(string)
Defines new patterns. Equivalent to @define{string}. gel.ruleclear(domain)
Delete all patterns defined in the specified domain. 4. Examples prev top

Here you will find some short examples on:

Definining lua functions
Returning values from lua
Accessing gema variables
Parsing from Lua The best way to see GeL in action is to have a look at the example directory in the distribution package.

4.1 Defining lua functions

There are three methods for having lua functions defined:

Write the functions in a file and execute it through the command line -lua option
Write the functions in a file and execute in an action through the @lua{} function. This method also allows you to load a different set of lua functions depending on a match.
Embed the lua functions in the gema file using the new syntax "![" "!]" Here you will find the same task solved using the three methods.

Consider the following task as an example of a function not available in gema (it could have been any other function not easily definable in gema):

Find numbers in a file and create another file with every number replaced by its logarithm (if n > 0) or by the string "-infty" (if n

Similar Documents

Free Essay

Roles Involved in Network Security

...Unit 9 Assignment 1: List phases of a computer Attack Reconnaissance and Probing The primary attach would be pretending to be friendly to a user by simply starting with a story or a joke to a co-worker, to get some type of information, then a search through different means (google, social sites, etc.) Method of access 1. The primary target is to use some type of phishing, spear or pharming type of trick to get information (use a birthday, anniversary, etc.). I could pose as an outside contractor that just happen to have lost its private key accidentally and need to access the system through one of the company computers connected to the network. 2. Using social engineering by offering to send the postcard by email (attachment) containing the invitations to the manager’s birthday party and the need to confirm their attendance by replaying back through their email addresses. Opening the attachment by the users would place some type of spyware to get habits and web activities. 3. Eventually I could land with some valuable information that would affect the individual’s privacy and confidentiality. Then I could have gain access to the system. Next phase of attack: • Use hping/2 to test the firewall, hping offers an IP spoofing scan while monitoring a target’s response to seduce discovery information such as distinguishing between different firewall policies and active services. • I would use Nessus Security Scanner with a tool providing a Scripting Language (NASL)...

Words: 430 - Pages: 2

Free Essay

Developing 2d Games

...enhance a broader category of users. Over the years, development of mobile games involved hard work. Professional software developers and programmers were hired by companies to develop games and it also consumed a great amount of time to bring perfection in a game. But recently, it is seen that independent developers and also people with very little or no programming knowledge are building games and application on a regular basis and many of those games were not only being played but also received tremendous amount of success as well. For example, 14 year old Robert Nay developed Bubble Ball which literally knocked the famous Angry Birds down from top position. In this study, review will be conducted about a scripting language called Lua, which is used to develop games and applications and a review about Corona SDK, which is a...

Words: 3241 - Pages: 13

Premium Essay

Creative Writing: A Cross-American Race

...Coach tries to pump everyone up for the big race tomorrow but all you can hear are the sniffles coming from all the the runners. Everyone shivers as a cool, fall breeze passes through the group. As coaches speech drags to an end we all thank him, and get our stuff to leave. Everyone jokes around per usual, though there is a dense fog of stress hanging in the air. Tomorrow is the biggest cross country race of the season. If the team does good then they get to stay running for another week and go to regionals, but if they have a bad race their season will end right there without states. As Sarah returns home from practice with her older brother Adam, she remembers her last race. She remembers how little water she drank and how much it affected...

Words: 1859 - Pages: 8

Free Essay

Case Study

...Punjab, Recognized by HEC) Assessment Disclosure Assignment One • Dead line for the submission of first assignment as on Friday 20th April 2012 at 4:00pm sharp. All the stuff can be submit at my office F10 in to my absence Mr. Anjum or Mr. Haroon (office staff). • All the material must be hand written. • The given task helps you to acquire excellent grades into quizzes, mid and final as well. 100% Guarantee! • The following list of question require to accomplish the first task from course pack of financial accounting l; 1. Theoretical question:- 1, 3, 5, 6, 8, 9, 10, 11, 12, 13, 14 (pg. 23-24) 2. Problems:- 1, 2, 3, 4, 5 (pg. 27-28) 3. Illustrations:- 3.1, 3.2 (pg. 31, 34) 4. Objective:- 1, 2, 3, 4, 5, 6, 7, 8 (pg. 36-38) 5. Illustration: 2, 3 4 (pg. 24-25) 6. Problems:- 1, 2, 3, 4, 5 (pg. 26-28) 7. Comprehensive Illustration:- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 (pg. 42-47 Note:- Apparently, the course pack brings it up from different authors practice material therefore please, patiently looks at your course material to find all the above relevant pages numbers accordingly and also particular practice material. Assignment Two • Dead line for the submission of second assignment as on Friday 2nd May 2012 at 4:00pm sharp. All the stuff can be submit at my office F10 in to my absence Mr. Anjum or Mr. Haroon (office staff). • All the material must be hand written. • The given task helps you to acquire excellent...

Words: 409 - Pages: 2

Premium Essay

Road

...Rennalls is a talented engineer, on the other hand he has a conflict with expatriates. • On the one hand Rennalls can influence the policy of the Co by his father, but on the other hand he is not the only candidate. • On the one hand Baker wants Rennalls to work for the Co, but on the other hand the Co can’t risk his image. 2. Options 1) Hive apologizes to Rennalls and invite him back to the company. Advantages: • Rennalls is a professional worker. He can influence the policy of the Co on the islands. Disadvantages: • His racial conflicts with the stuff. • Rennalls is sometimes rude with staff and that causes negative emotions in the collective. 2) To find out another candidate for Rennalls place. Advantages: • Taking a Barracanian substitute for the place. It may solve the problem of Rennall’s stuff rudeness. Disadvantages: •...

Words: 472 - Pages: 2

Free Essay

Suboxone Prescriptions

...Make sure to bring down laptop, laptop charger, wireless mouse, cell phone and flash drive – copy over all the stuff from the “Kevin’s Stuff” folder on Doug’s computer to the flash drive. ***Call Dr. Reddy back first thing in the morning if I haven’t heard by then (336-662-8185) 1. Rizwan Ali: Advanced Psychiatric Services 2727 Electric Road, Suite 103 Roanoke, VA 24018 540-772-1974 Have to go for first appointment to be assessed then go back for a second appointment to be inducted into the program. Insurance will most likely pay for first (assessment) appointment, but the suboxone is on a cash only basis. $500 for first month and price will come down each subsequent month. Includes group sessions. a. First appointment (assessment) – Monday, Feb. 6 @ 1pm b. Second (suboxone induction) – Wednesday, Feb. 8 between 4-6pm Someone is supposed to call back after 11am tomorrow, Wednesday, Feb. 1, to let me know if I’m a good candidate and to confirm appointments. * ***If I haven’t heard anything by first thing in morning (9AM), call Dr. Reddy’s office to determine if she can change the existing appointment (tomorrow, Wednesday, Feb. 1 @ 5pm) from a regular appointment to a suboxone appointment. * **Someone is supposed to call back after 11am tomorrow (Wednesday) to verify appointments from Dr. Rizwan Ali’s office (540-772-1974) * *In morning, call the rest of the physicians I haven’t gotten in touch with, including the physicians listed...

Words: 340 - Pages: 2

Free Essay

Freedom to Comment

...against the group happened when I was in college. I worked at clothing store at the local mall. One of the requirements for working there was that you had to wear the clothes that were sold there or clothes similar to them. After working there for a month or so I stumbled upon a few of the girls taking clothes off the shelf and putting them in the back room. I was then told that sometimes the girls there would “borrow the clothes and wear them to work in that day and then put them back on the shelf for customers to buy. I did speak up and tell them I thought it was wrong. They then informed me that even the manager of the store did it. That she would even get merchandise and take it home and keep the tags there and pay for some of the stuff a little bit along. I was in shock. I proceeded by calling the home office and calling the district manager and reporting the issue. A few weeks later the district manager came in the store. I was then fired. All the girls told the district manager that I was causing arguments within the group and I was a trouble maker. I did find out later that the home office did their own investigation in the store and all of the girls even the manager ended up getting fired. Even though I was fired from the job, I felt good about doing the right thing. I could have easily conform to the group for the sake of my job but due to my ethical beliefs I could not do...

Words: 353 - Pages: 2

Free Essay

The Stuff

...the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here the stuff is in here ...

Words: 1500 - Pages: 6

Free Essay

Moving to a Different Country

...Steps to Moving to a new country Mayar Lampkin Everest University Ever wonder what it is like to move to a new country? Well wonder no more I will tell you. Moving to a new country can be fun and exciting adventure but it takes a lot of work and planning. Before you go and experience the new culture make sure you do research on the country. Another is to make sure you have the right paper work and documentation. The last step is to make sure you pack up essentials. It sounds like a lot and hard work but in the end it is all worth it. Doing research about the country you will live in is very important because you will be informed about the cultures and customs of the country. Also researching what cities are safe to live in and what cities are dangerous is good way of keeping yourself safe and out of trouble. Make sure to research living situations is it mostly apartment/condo living or is it houses? Knowing that information is good for when you are packing because you will know how much space you will have. A good way of research is finding a group on a social media website and asking them questions about the country and living situations. This step will be the most important step out of all three. Having the right paperwork and documentation is very important or you can get in serious trouble and or road blocks along the way. Making sure you know what you need is important. For example if you do not already have a passport make sure you apply for one right...

Words: 629 - Pages: 3

Premium Essay

Case Hell

...Rennalls is a talented engineer, on the other hand he has a conflict with expatriates. • On the one hand Rennalls can influence the policy of the Co by his father, but on the other hand he is not the only candidate. • On the one hand Baker wants Rennalls to work for the Co, but on the other hand the Co can’t risk his image. 2. Options 1) Hive apologizes to Rennalls and invite him back to the company. Advantages: • Rennalls is a professional worker. He can influence the policy of the Co on the islands. Disadvantages: • His racial conflicts with the stuff. • Rennalls is sometimes rude with staff and that causes negative emotions in the collective. 2) To find out another candidate for Rennalls place. Advantages: • Taking a Barracanian substitute for the place. It may solve the problem of Rennall’s stuff rudeness. Disadvantages: •...

Words: 472 - Pages: 2

Free Essay

Fancial Accounting

...Punjab, Recognized by HEC) Assessment Disclosure Assignment One • Dead line for the submission of first assignment as on Friday 20th April 2012 at 4:00pm sharp. All the stuff can be submit at my office F10 in to my absence Mr. Anjum or Mr. Haroon (office staff). • All the material must be hand written. • The given task helps you to acquire excellent grades into quizzes, mid and final as well. 100% Guarantee! • The following list of question require to accomplish the first task from course pack of financial accounting l; 1. Theoretical question:- 1, 3, 5, 6, 8, 9, 10, 11, 12, 13, 14 (pg. 23-24) 2. Problems:- 1, 2, 3, 4, 5 (pg. 27-28) 3. Illustrations:- 3.1, 3.2 (pg. 31, 34) 4. Objective:- 1, 2, 3, 4, 5, 6, 7, 8 (pg. 36-38) 5. Illustration: 2, 3 4 (pg. 24-25) 6. Problems:- 1, 2, 3, 4, 5 (pg. 26-28) 7. Comprehensive Illustration:- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 (pg. 42-47 Note:- Apparently, the course pack brings it up from different authors practice material therefore please, patiently looks at your course material to find all the above relevant pages numbers accordingly and also particular practice material. Assignment Two • Dead line for the submission of second assignment as on Friday 2nd May 2012 at 4:00pm sharp. All the stuff can be submit at my office F10 in to my absence Mr. Anjum or Mr. Haroon (office staff). • All the material must be hand written. • The given task helps you to acquire excellent...

Words: 410 - Pages: 2

Premium Essay

Paper

...20 September 2011 Topic Proposal The topic that I am using from the Affluenza book is Stuff Wars at the Airport on page 35. The angle that I am approaching this topic is from an airport employee stance. I worked at an international airport in several different capacities and think it provides a unique perspective. My guiding questions will be the basic such as: * What is the topic? * Why has this topic been chosen? * What is the focus of the topic? * How is the perspective and understanding conveyed to the reader? The concerns for this topic are the type of information that can be found other than personal experiences but believe that resources can be found in several areas on the internet, online databases, and library. Deciding on how specific is another concern, but believe that staying within the confines of the stuff wars specifically at the airport will keep the topic within the boundaries of the project. It is difficult to determine the time frame it will take to research the topic. It will take approximately two weeks to come up with an appropriate thesis and outline for the project. It could take two weeks to focus the topic on specific questions to ask but as soon as that is complete, it is easy to make a list of factual and interpretive questions for the reader to understand the research. After all has been completed, the research has a good foundation and is ready to start. To complete the essay will take one week to compile, rewrite, and finish...

Words: 474 - Pages: 2

Premium Essay

Costs of Goods Sold

...of the inventory. When everything is said and done it equals out to the cost of the goods that have been sold. Cost of goods sold is the accumulated total of all the costs used to create a product or service in this case it is which has been sold. All of these costs fall into a general sub category of direct labor as well as the materials, and overhead stock. The cost of goods sold is considered to be a part of the labor and payroll taxes. Beginning Inventory |+ |Purchases |- |Ending Inventory |= |Cost of Goods Sold | |$600 |+ |$1500 |- |$400 |= |$1700 | |$800 |+ |$2400 |- |$600 |= |$2600 | |There is also a first in and first out method that helps with keeping track of the inventory. So when things come in the stuff that is older should move forward and the new stuff should go in back. I believe that when it comes down to it the way we handle the sales of the products then the company should not have a problem with keeping track of the funds coming in and going out. Below I have added the example of how it should work. I have done two different...

Words: 272 - Pages: 2

Premium Essay

Hrm 531 Week 2 Individual Reflection Journal

...living situation and her background. When he was done talking with the client, we started the paperwork. I started asking the questions on the forms, my supervisor would step in to explain something or ask more questions. After the initial paperwork was filled out we had to go over forms that the client had to sign. Although I was able to remember some of the stuff on the forms, I was unable to remember everything on them, so my supervisor stepped in to better explain the forms. In the end the intake took around an hour to complete. After the intake, my supervisor stated that I did okay, just that I need to work on being able to explain LINK services and what the paperwork states, as well as being more comfortable exploring with questions. During the intake, I felt pressure to be able to explain things properly, which is partially the cause of forgetting things. I also felt that I wasn’t really given that much opportunity to explore some of the questions because my supervisor took over. It was almost as if I was thinking too much into it and was too worried about during the intake properly that mind spaced on some of the stuff that I was supposed to go over. As far as the NASW Code of Ethics, there are a few values or principles that were evident in the situation. The first one deals with competence, although it is important to be knowledgeable and apply past experience into practice, it can be hard sometimes. Since I am still in the learning process, I need to accept that not everything...

Words: 737 - Pages: 3

Premium Essay

The Story of Stuff Review

...“The Story of Stuff” is a short video created by The Story of Stuff project in 2007. In the video, writers Annie Leonard and Jonah Sachs describe the process of turning natural resources into consumer goods, then into waste. The writers describe a seemingly linear five-step process: extraction, production, distribution, consumption, and disposal. Leonard and Sachs describe a carefully-scripted culture of unsustainable consumption and waste. The extraction phase of “The Story of Stuff” refers to the removal of natural resources such as timber, natural gas, coal, oil, and water. The writers emphasize the unsustainability of this phase, especially in the United States. The video states that the United States holds 5% of the world’s population but uses 30% of the world’s natural resources and creates over 30% of the world’s waste. This is a staggering statistic. Four percent of the United States’ forests remain. FOUR PERCENT. How much longer will it be before trees are things read about in storybooks (digitally printed of course, as there are no more natural resources to harvest.) The production phase is described as the addition of toxic chemicals to natural resources in order to produce the “stuff” we want. Please note the use of the word “want,” not “need.” The authors note that over 100,000 synthetic chemicals are commercially available today and are regularly used in production. Of those 100,000 synthetic chemicals, very few have been tested in a significant way to measure...

Words: 1034 - Pages: 5