Lua Language
#1
Posted 11 August 2006 - 11:23 AM
If it exists, can you tell me the direction?
If it doesn't exist I try read in Inglish, but I'm not sure if then I will can program in CPLua...
Thanks for all.
#2
Posted 12 August 2006 - 05:17 AM
Can someone tell me if exists a document about the Lua language in Spanish?
If it exists, can you tell me the direction?
If it doesn't exist I try read in Inglish, but I'm not sure if then I will can program in CPLua...
Thanks for all.
I have not seen any document in spanish I think only portuguese and english...
#3
Posted 06 September 2006 - 12:19 PM
Lua is'nt popular yet
#4
Posted 06 September 2006 - 01:54 PM
#6
Posted 10 September 2006 - 02:59 PM
I have one simple question, in pag 14 of pdf named you can see:
-- defines a factorial function function fact (n) --more lines print("enter a number:") a = io.read("*number") -- read a number print(fact(a))
When I run this lines in my emulator, it shows me a error message, the problem is in io.read, I have to load the function? io.read is like an input?
In the file functions (is in the .rar when you download CPLua) I have found:
IO:
io.folder() + folder management:
fold:exists(), fold:create(), fold:remove(), fold:rename(),
fold:name(), fold:content()
io.file() + file management:
fi:exists(), fi:create(), fi:remove(), fi:rename(), fi:copy(),
fi:header(), fi:folder(), fi:name(), fi:size(), fi:open(),
fi:isopen(), fi:write(), fi:read(), fi:eof(),
What is this? What is the use of this file? It has the answer of my io.read problem?
Yes I'm starting in Lua. Sorry for my novice questions.
#7
Posted 10 September 2006 - 03:28 PM
#8
Posted 10 September 2006 - 04:39 PM
I really need to write something for CPLua beginners...
#9
Posted 10 September 2006 - 04:49 PM
The book "Programming in Lua" is good to discover the features and possibilities of the Lua language... However you must know that there are a lot of differences with the libraries and packages implemented in CPLua. In CPLua there is no function "io.read()", but instead you have a function "input()" that you could use to ask for a string or a number. The file "functions.txt" lists all the functions that are specific in CPLua
I really need to write something for CPLua beginners...
sure. I can restart the tut that i begun some months ago. The forum needs a pinned FAQ for newbies, too many questions, the same questions.. i will start the topic now
#10
Posted 10 September 2006 - 06:57 PM
I agree with that , i think its needed. Hope the afx master could help you, its a lot of work for one person, to develop, make faqs etc...I really need to write something for CPLua beginners...
#11
Posted 13 September 2006 - 10:08 AM
--first with numbers a=1 b=a print(b) --> 1 ok b=2 print(a) --> 1 ok --now with tables a={} a[1]=1 b=a --b is equal to a, but a should remain equal to 1 (for me) print(b[1]) --> 1 ok b[1]=2 --now b=2, but a should remain equal to 1 print(a[1]) --> 2 not ok
someone can tell me why??
PD: I usually use matlab.
#12
Posted 13 September 2006 - 11:57 AM
Fortunately, there is a solution: Orwell has added a very useful function in CPLua; it's called table.copy, and does what it is obvious from its name: b=table.copy(a) creates a new table b (not a pointer to a), so that changes in b don't affect a. Conclusion: use b=table.copy(a) instead of b=a (unless you want to create a pointer -- but usually you don't want such a thing).
Note that if a is a number, b=a does not create a pointer, but a new real variable b. That's why you don't see strange results in this case.
Btw, AFX_Master, you should add such an explanation to your CPLua tutorial.
PS: Matlab is good, but it's also an expensive commercial product; my opinion is to use Scilab or Octave instead.
#13
Posted 13 September 2006 - 12:57 PM
The problem is that you are viewing the Lua tables from the mathematical point of view (and it's perfectly normal, since you especially care about maths in your programs). You may not forget that math programs represent only a very small part of what you could do with a general-purpose programming language (like Lua).
Like I said before, tables and matrices exist (in different forms) in most decent languages. And in most cases (at least 80%), the programmer wants to be able to manipulate several references to the same table.
Create implicit copies of matrices would require a lot of time and memory, and most programmers won't need this feature and won't accept to lose time and memory for that. Thus, the default behaviour is that tables are not implicitely copied, but there is a function that you may use (explicitely) if you really need to spend time for a copy.
It doesn't sound strange to me; this is exactly what I need as a "general-purpose programmer". Pointer manipulation is one of the most powerful features of this kind of languages.I know it's strange and annoying, but this is how it works.
That's correct... C++ just don't care about matrices. I never need matrix manipulation in my C++ programs, because those are features designed for math programs, and I don't write any math programs myself (like 90% of the other C++ programmers). However, if I somehow need such a feature for my program, I just have to write or import a library to add matrix support, and everything will be fine.Lua is similar to C/C++ in matrix handling; this means that it has very poor matrix support.
I do! And I'm not the only one(unless you want to create a pointer -- but usually you don't want such a thing)
I agree. People should know what they are exactly doing when manipulating Lua tablesBtw, AFX_Master, you should add such an explanation to your CPLua tutorial.
#14
Posted 13 September 2006 - 05:42 PM
If only there was something like PHP available for general purpose scripting even without all its builtin libraries PHP is better than LUA is my opinion...
#15
Posted 13 September 2006 - 05:46 PM
Well I'm reading programming whit Lua (it's very very long) when I have time the reading goes on. I will make my questions about that here, (I will think in my doubt before post my question), in this wey you can know the doubs of novices of Lua. If someone answer my questions I will thank for it.
I have a litle question: I understand the function braek, but function return seems to be equal, what is the differences between them??.
#16
Posted 13 September 2006 - 06:20 PM
There is a "powerpatch" to add the "continue" statement in Lua. If several people are interested I can try to apply it on CPLuaand also the fact that the "continue" statement doesn't exist !
Btw there is also a patch to optimize the use of integer numbers (with this you don't have to use floating point numbers to store integer values). I'll make a few tests later to see if it would be interesting for CPLua.
If "a" is a table, you should actually think that "a" is only a variable which holds the adress of the real table. Then if you write "b=a", you only copy the table's adress into b, not the table itself. Thus "a" and "b" refer to the same adress and thus to the same table. It's the same thing for functions and userdata's.Ok I think that I have caugth the idea. In Lua, if a and b are tables, when you put a=b it implies b=a & a=b; but if a & b are numbers, a=b doesn't imply b=a. That's it?
"break" is useful to break a loop, while "return" breaks a function.I have a litle question: I understand the function braek, but function return seems to be equal, what is the differences between them??.
For example:
function example() -- wait for the user to press left or right arrow while 1 do if testkey(K_RIGHT) then break end -- break the "while" loop when right arrow is pressed else if testkey(K_LEFT) then return "left" end -- return from the function end return "right" endPS: Note that this example is very bad programmed.
A better code would be
function example() -- wait for the user to press left or right arrow local le, ri = false, false repeat le = testkey(K_LEFT) ri = testkey(K_RIGHT) until le==true or ri==true if le==true then return "left" else return "right" end end
#17
Posted 13 September 2006 - 06:26 PM
Btw, AFX_Master, you should add such an explanation to your CPLua tutorial.
Sure, i'm in tables now, i will post in a few minutes. As far i know, if you need to copy a table, you need to use table.copy(), or do a loop over the table (agh!... so boring! ).
#18
Posted 14 September 2006 - 07:50 AM
This argument has been used by all C/C++ programmers worldwide, again and again... I know why; because it's the only argument they can use. Their conclusion is always the same: "I don't need matrices, they don't really exist in C, and I am happy with that; but even if I need them, I can use a matrix library". I totally disagree. What do you mean with "most" programmers? I can reply that most programmers in scientific programming use matrices all the time, because every aspect of Physics or Mathematics is full of matrices.Create implicit copies of matrices would require a lot of time and memory, and most programmers won't need this feature and won't accept to lose time and memory for that
I never (or almost never) use pointers, but I always use matrices.It doesn't sound strange to me; this is exactly what I need as a "general-purpose programmer". Pointer manipulation is one of the most powerful features of this kind of languages.
That's correct... C++ just don't care about matrices. I never need matrix manipulation in my C++ programs, because those are features designed for math programs, and I don't write any math programs myself (like 90% of the other C++ programmers). However, if I somehow need such a feature for my program, I just have to write or import a library to add matrix support, and everything will be fine.
Ok, it seems that we are starting a debate concerning which programming language is better. We have done such a debate in the past, and it's totally meaningless to start again. I hope that we can at least agree with that: scientific programming can be done in C++, but nobody wants to do that, because Fortran 95 is much better for Mathematics. On the other hand, nobody wants to write an operating system in Fortran; it can be done, but C++ can do it much better.
#19
Posted 14 September 2006 - 08:25 AM
Remember the example I gave earlier: You can have a nice, superfast car, but you will never want to cross the oceans with it Programming languages are designed for specific purposes, and they are optimized with consideration for these purposes.scientific programming can be done in C++, but nobody wants to do that, because Fortran 95 is much better for Mathematics. On the other hand, nobody wants to write an operating system in Fortran; it can be done, but C++ can do it much better.
#20
Posted 14 September 2006 - 09:00 AM
Remember the example I gave several months ago: Developing mathematical programs in C++ instead of Fortran 95 is like this: you have a Fiat Panda and a Lamborghini Countach, you want to go from Paris to, say, Moscow, and you take Fiat Panda instead of Lamborghini .Remember the example I gave earlier: You can have a nice, superfast car, but you will never want to cross the oceans with it Programming languages are designed for specific purposes, and they are optimized with consideration for these purposes.
#21
Posted 14 September 2006 - 09:16 AM
This comparison is good for CPBasic and CPLua, because these are languages with the same purposes but with big differences in performance.Remember the example I gave several months ago: Developing mathematical programs in C++ instead of Fortran 95 is like this: you have a Fiat Panda and a Lamborghini Countach, you want to go from Paris to, say, Moscow, and you take Fiat Panda instead of Lamborghini .
Suppose Fortran is a car and C++ is a boat
You can ride from Paris to Moscow with your car, and I can sail from France to USA with my boat.
I can go to Moscow if I want, I just have to add wheels to my boat. But of course I won't be as fast as your car. And you could go from France to USA too, if you add some floats to your car. But I bet you won't be as fast as my boat I think this clearly illustrates the debate
#22
Posted 14 September 2006 - 09:24 AM
Indeed .This comparison is good for CPBasic and CPLua, because these are languages with the same purposes but with big differences in performance.
Excellent! I totally agree.Suppose Fortran is a car and C++ is a boat
You can ride from Paris to Moscow with your car, and I can sail from France to USA with my boat.
I can go to Moscow if I want, I just have to add wheels to my boat. But of course I won't be as fast as your car. And you could go from France to USA too, if you add some floats to your car. But I bet you won't be as fast as my boat I think this clearly illustrates the debate
#23
Posted 14 September 2006 - 09:46 AM
Une bonne voiture roule toujours plus vite qu'un bon bateau avec des roues
#24
Posted 14 September 2006 - 12:20 PM
#25
Posted 17 September 2006 - 02:53 PM
Other thing: I create a simple pictur like this:
require ("draw") pic = pict.new(5,5) draw.onscreen()
But nothing apears.. how can I see this pictur in the screen?
#26
Posted 17 September 2006 - 04:44 PM
If you want to use your function in another file than main/name, you must export it explicitely at the end of main/name.For example I create one function, and save it in the folder: main/name; then I want to use this function in other file, I write on the top: require ("main/name"), but the function doesn't work, why?
For example:
-- FILE "main/name" function example() print("hello!") end export{example=example} -- exports "example" -- other file: require("main/name") -- imports "example" from main/name example()
pic = pict.new(5,5) is just creating a new picture called "pic". This picture is not drawed at that time. With draw.onscreen() you just indicated that drawing operations must be sent to the screen. But you must use draw.pict() too to make the picture appearOther thing: I create a simple pictur like this:
require ("draw") pic = pict.new(5,5) draw.onscreen()
But nothing apears.. how can I see this pictur in the screen?
Note that a new picture is white by default, thus you wouldn't see it on a white screen.
An example is
require ("draw") pic = pict.new(5,5) draw.onpict(pic) -- draw on the picture draw.rect(0,0,4,4) draw.onscreen() -- now draw on the screen draw.pict(10,10,pic) -- make the pict appear
#27
Posted 18 September 2006 - 12:56 PM
require ("draw") pic = pict.new(5,5) draw.onpict(pic) -- draw on the picture draw.rect(0,0,4,4) draw.onscreen() -- now draw on the screen draw.pict(10,10,pic) -- make the pict appear
#28
Posted 18 September 2006 - 01:52 PM
Then add this at the end:Ok the function in other file works perfect with export. Sorry, but I write this code, and nothing apears, only Done.
showgraph() -- show the graph window waitinput() -- wait for a key
Btw, reading the examples could be instructive
#29
Posted 02 October 2006 - 08:36 PM
require('LNA/TrapAd') function f(x) return math.exp(3*x) end q=TrapAdapt(f,0,3) print(q)
My class pad 300 doesn't respond, (it's many time thinking and nothing is shown)* I think it's wouldn't have to be difficult for LUA, if I use Romberg instead TrapAdapt happens the same.
Can it be the memory?? what can I do? I have 415108 free bytes, I think it is sufficient.
*In spanish: que se me cuelga
#30
Posted 02 October 2006 - 09:47 PM
As far i know, the Storage RAM (415108 bytes free) is totally independant from calculation RAM (1.2 mb in O.S 2.2). when the memory fills up, you see an "Alloc Failed" message, sure, isn't memory problemCan it be the memory?? what can I do? I have 415108 free bytes, I think it is sufficient.
*In spanish: que se me cuelga
Could be:
-waitkey(), waitpen(), waitinput() functions running (check it if your code is bigger than the sample that you posted)
-Your'e on graph window, you can activate the console on the code with showconsole()
but the probability of the last issues that i mentioned is a silly 1% . And sure isn't a time consuming operation (the CP CAS give the result in a blink ).
Wait for PAP, he's the owner of PAP MICROSYSTEMS, and he could help you.
PD: Hey PAP, what about state PAP MICROSYSTEMS , joke
#31
Posted 03 October 2006 - 04:39 PM
If I undestand Storage RAM doesn't affect to calculation speed, but calculation RAM yes, and is 1,2 mb in OS 2.2. This calculation RAM is always 1,2?? There are any form to increase this calculation RAM??
Other question: there are any form to delate geometry, conical, sequences, presentation aplications?? I don't use them.
#32
Posted 03 October 2006 - 07:15 PM
Of course not: does the free space on your hard disk help your processor to run faster? These are completely different things...If I undestand Storage RAM doesn't affect to calculation speed, but calculation RAM yes
Execution speed has nothing to do with the size of free memory space (RAM or Storage).
Hey, it was 180 Kb in CPLua 0.9B, it's now 1.2 Mb in the current version, and you still want more?and is 1,2 mb in OS 2.2. This calculation RAM is always 1,2?? There are any form to increase this calculation RAM??
#33
Posted 03 October 2006 - 09:32 PM
Hey, it was 180 Kb in CPLua 0.9B, it's now 1.2 Mb in the current version, and you still want more?
Ok Ok I compared it with my PC RAM (512 Mb), but I suppose that CP isn't a PC, I believe you.
When we can get CPLua 0.9? And LUA 1.7? Or it's now available and I had not found out? (I only ask, you can get your time)
#34
Posted 04 October 2006 - 06:01 PM
p=0.3-0.4 h=1.2-1.3 print(p==h) --> false ?????????? :banghead: p=0.7-0.8 print(p==h) --> true ok
Is my CP?? What happens?? p=-0.1, h=-0.1 print(-0.1==-0.1) --> no ??
#35
Posted 04 October 2006 - 07:18 PM
According to the developer (Orwell), CPLua is in version 0.9D. If I understand well, this is a pre-pre release candidate.When we can get CPLua 0.9? And LUA 1.7? Or it's now available and I had not found out? (I only ask, you can get your time)
The only person who has LNA version 1.70 is me , because I haven't released it yet. I'm still trying to find the time needed to update the documentation, hence the delay...
#36
Posted 05 October 2006 - 09:19 PM
p=0.3-0.4 h=1.2-1.3 print(p==h) --> false ??????????
Please can someone help me with this??, p and h are equal to -0.1, and my CP says that they are different. It's only my CP?? What's happens??
And what's about my question: it's normal that my CP takes 2 min to do Romberg(f,0,3); f=math.exp(3x)??
#37
Posted 06 October 2006 - 07:49 AM
First of all, your CP isn't different from the other ones. If you get some strange results, then most people should have the same thing.
And second, this is not a bug... It's the correct result :/
CPLua uses floating point numbers as basis type for numbers, that means that it only uses some good approximations of the exact numbers.
For example, "0.3" for you might be "0.299999999999" for CPLua.
If you do "print(0.3-0.4)", you will see -0.1, but the exact result was perhaps -0.10000001. CPLua rounds the number to -0.1 for lisibility.
But if you do "print(1.2-1.3)", you will also see -0.1, but perhaps the exact result was -0.99999999.
Then if you compare the 2 results, CPLua will tell you that these numbers are not equal. And this is correct
I know it is very disturbing. Unfortunately I can't correct this effect
Everytime you use decimal numbers, you must think that the equality operator "==" could return some unexpected results. If you really want to compare two real numbers A and B, you should write something like "abs( A-B )<eps" where "eps" is a really small number.
It sounds weird I know, but this is how computers work (not only the CP)
Then why isn't there any error if you try the same thing in the Main Application? (or even with the CAS package; try this:
require("cas") A = cas("0.3") B = cas("1.2") print( (A-0.4)==(B-1.3) ))
Simply because the CP uses BCD numbers for the CAS instead of floating points numbers (for better precision). Unfortunately, it is a lot slower
PS: actually I have a suggestion about this, but I'll post it in the "Suggestions" topic later
#38
Posted 06 October 2006 - 02:35 PM
#39
Posted 06 October 2006 - 09:06 PM
(Sorry for answering late, but I didn't noticed your post before)One problem whit LUA, in this code:
require('LNA/TrapAd') function f(x) return math.exp(3*x) end q=TrapAdapt(f,0,3) print(q)My class pad 300 doesn't respond, (it's many time thinking and nothing is shown)* I think it's wouldn't have to be difficult for LUA, if I use Romberg instead TrapAdapt happens the same.
Can it be the memory?? what can I do? I have 415108 free bytes, I think it is sufficient.
Well, there is no problem here: TrapAdapt tries to compute your integral with the default accuracy, which is 1E-6. In this case, this accuracy is very large, since the correct result is (exp(9)-1)/3=2700.69, which is huge, compared to 1E-6. You can obtain a very accurate result by reducing accuracy, using the optional argument eps. For example, setting eps=0.01 gives 2700.70 in about one second. Note that the result has an error equal to 0.01, as requested.
Btw, memory is not a problem here, no matter what accuracy you choose.
Yes, it is normal, for the same reason. Note that Romberg is in general faster and more accurate than TrapAdapt, but not always (read the manual for details). Set eps=0.01 to get a very accurate result easily.Ok I wait more time and the class pad takes 2 min, more or less, to do Romberg(f,0,3); f=e^(3x). Is it normal?? It is faster if I change function, for example: f=1/((1-x)*(0.05+0.5*x))
In general, if an LNA computation needs a lot of time, reduce accuracy, then increase it slightly, and compare the results given.
Prease remember that Numerical Analysis is an art, but it's not magic. There is no computer system which is able to solve any problem numerically with great accuracy and in no time.
--> PS: I think that you should post those questions to the LNA topic. LNA is a library written in CPLua; it's not part of the Lua language.
I like your sense of humor, although "MicroSystems" reminds me Micro..ft, which is disgusting.Wait for PAP, he's the owner of PAP MICROSYSTEMS, and he could help you.
PD: Hey PAP, what about state PAP MICROSYSTEMS , joke
#40
Posted 07 October 2006 - 12:13 PM
I solved my floating point numbers and Romberg problems.
--> PS: I think that you should post those questions to the LNA topic. LNA is a library written in CPLua; it's not part of the Lua language.
Ok I post my LNA doubts in Cplua Project: Luanuman.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users