not (yet) real object oriented stuff
#1
Posted 04 May 2014 - 03:20 PM
please note, English is not my first language.
#2
Posted 04 May 2014 - 05:21 PM
Also try looking at http://pastebin.com/t0Nb6pbS, it might help you understand OOP in Lua a bit
Edited by HometownPotato, 04 May 2014 - 05:21 PM.
#3
Posted 04 May 2014 - 06:24 PM
and I know I can make my own functions and use them multiple times, but I want to make whole API's which I want to be able to trash, rewrite and replace as a whole. (like an object.) I just don't know how.
#4
Posted 04 May 2014 - 06:41 PM
#5
Posted 04 May 2014 - 06:46 PM
How do you bind a value to the scope of a program, and after executing be able to get the value back once you execute the program another time.
And how could you make that last impossible for other programs?
or am I asking something impossible?
edit:
I know what the Vector API does and don't want to use it because I don't need to.
It doesn't have anything in common with my problem.
Edited by blipman17, 04 May 2014 - 06:48 PM.
#6
Posted 04 May 2014 - 06:59 PM
file:myprogram
dofile("myapi")
test=api:new()
test.hello()
file:myapiapi={
new=function(this)
object={}
setmetatable(object,this)
this.__index=this
return object
end,
hello=function()
print("hello world!")
end,
}
Edited by viluon, 04 May 2014 - 07:00 PM.
#7
Posted 04 May 2014 - 07:14 PM
blipman17, on 04 May 2014 - 06:46 PM, said:
It doesn't have anything in common with my problem.
#8
Posted 04 May 2014 - 07:47 PM
#9
Posted 04 May 2014 - 10:40 PM
Edited by blipman17, 04 May 2014 - 10:41 PM.
#10
Posted 04 May 2014 - 11:04 PM
blipman17, on 04 May 2014 - 06:46 PM, said:
blipman17, on 04 May 2014 - 06:46 PM, said:
or am I asking something impossible?
blipman17, on 04 May 2014 - 10:40 PM, said:
blipman17, on 04 May 2014 - 10:40 PM, said:
Object-Oriented programming is aimed at being able to make 'objects' which to put it simply allow you to do two things. The first things is it allows you to hide implementation details, for example you could have a method that calls various other methods during its process, and accesses some hidden variables, and the person invoking the original method could be none the wiser of its implementation, just the result (this is called encapsulation). The second thing it allows is for you to be able to make instances (objects) of your code, each having their own variable scope meaning any variable you change in an Object only changes for that object, not any other instance.
Now in terms of persistence... In ComputerCraft the only data that is persistent across program restarts is any variable in the global scope, however do note the global scope isn't persistent across computer restarts. Your best bet for persistence is to write the information you need out to file.
blipman17, on 04 May 2014 - 06:46 PM, said:
It doesn't have anything in common with my problem.
#11
Posted 05 May 2014 - 08:07 AM
#12
Posted 05 May 2014 - 01:10 PM
http://www.lua.org/pil/16.html
For me it was amazing what Lua has all "undercover" to surprise.
The most tricky thing (what I've never seen bevore in any other Language) is the . and : Notation. Please note that or you will struggle about Lua's OOP.
#13
Posted 05 May 2014 - 11:39 PM
steffomio, on 05 May 2014 - 01:10 PM, said:
local vec = Vector.new(1,1,1) --# colon notation print(vec:round()) --# dot notation print(vec.round(vec)
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











