NoHero Posted March 10, 2014 Share Posted March 10, 2014 I was looking at sol's stats logger lua script and couldn't understand one thing, i hope it can be explained by someone. In the extra lib dblib.lua the table containing the functions, each function uses a variable called 'c' what is this? i.e: DB:Connect("dbname", "dbuser", "dbpassword", "dbhost", 3306) ['Connect'] = function ( c, DBName, DBUser, DBPass, DBAddr, Port ) require "luasql.mysql" c.env = assert( luasql.mysql() ) c.con = assert(c.env:connect(DBName, DBUser, DBPass, DBAddr, Port)) end, i hope sol doesn't mind me posting snippets what is c doing? some sort of namespace? Quote Link to comment Share on other sites More sharing options...
Zelly Posted March 10, 2014 Share Posted March 10, 2014 c would be the DB if I am correct. (not sure if this the correct format for rewriting that piece of code, but it might help you understand it)if you do DB:Connect("dbname", "dbuser", "dbpassword", "dbhost", 3306)then you are really doing DB.Connect(DB,"dbname", "dbuser", "dbpassword", "dbhost", 3306) function DB.Connect(self,DBName, DBUser, DBPass, DBAddr, Port ) -- so self is actually the DB table require "luasql.mysql" self.env = assert( luasql.mysql() ) self.con = assert(self.env:connect(DBName, DBUser, DBPass, DBAddr, Port)) end Disclaimer: I do not fully understand this part of lua yet, so I may have made a mistake. NoHero 1 Quote Link to comment Share on other sites More sharing options...
Sol Posted March 11, 2014 Share Posted March 11, 2014 (edited) 'c' argument is something like a class or struct pointer like in 'C'LUA doesn't have classes but it's something like it, also you can implement prototype of any variable to this kind of structure to keep unique variable name and get access from that self pointer.Here is the explanation: http://www.lua.org/pil/16.1.html Edited March 11, 2014 by solaЯ NoHero 1 Quote Link to comment Share on other sites More sharing options...
NoHero Posted March 11, 2014 Author Share Posted March 11, 2014 Ah i see thanks, confused me because when i looked at OOP in lua examples the class was constructed differently. I see now that there are a few ways of doing it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.