LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-13-2011, 08:29 PM   #1
fantasy1215
Member
 
Registered: Oct 2011
Posts: 75

Rep: Reputation: Disabled
lua function return problem.


I hope I post this thread in a right place. The code below, lua complains I didn't end the function with 'end' in line 5, but if I remove line 5 'return "trash"', it works fine.
Thanks in advance!

1 #!/bin/env lua
2
3
4 function abc(strin)
5 return "trash"
6
7 if strin == "hello"
8 then
9 print("hello");
10 return "hello";
11 else
12 print("abc");
13 return "abc";
14 end
15 end
16
17 abc("hello");
 
Old 12-13-2011, 10:42 PM   #2
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Hi.

Look here for explanation and example.

Quote:
For syntactic reasons, a break or return can appear only as the last statement of a block (in other words, as the last statement in your chunk or just before an end, an else, or an until).
You should write
Code:
do return "trash"; end
so as the `return' statement be the last one in the block.
 
1 members found this post helpful.
Old 12-14-2011, 06:59 PM   #3
fantasy1215
Member
 
Registered: Oct 2011
Posts: 75

Original Poster
Rep: Reputation: Disabled
Thanks so much, This problem really troubled me a lot! Apprieciate your reply!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH: Return from function problem in search script SilversleevesX Programming 4 09-23-2011 04:41 PM
problem with return function value in perl shifter Programming 2 02-23-2010 10:04 PM
Get return value of function mortonmorton Linux - Newbie 4 10-09-2009 09:54 PM
Problem in checking function return value viveksnv Programming 3 10-02-2008 01:17 AM
sh script: problem with return value in function jhwilliams Linux - Software 1 06-20-2007 11:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration