function getNameAndValue(a)
--it's pseudo code
name = a --where name is "key"
value = a --and value is 50
end
key = 50
getNameAndValue(key)
It is possible to do with one parameter?
My library for easy saving Slib! Try this! Now you can encrypt your save!
- Drop of light LD#30
- OUTRANGE LD#31 (Sorry for my english. I learn it myself, and I don't have enough experience)
I guess you could use the [manual]debug[/manual] library somehow, but it's probably the wrong thing to do. Why do you want the function getNameAndValue?
function getKeyAndValue(t)
local key, value
for k, v in pairs(t) do
key = k
value = v
break
end
return key, value
end
myTable = { key = 50 }
key, value = getKeyAndValue(myTable)
Thanks all. I want write small function for debug, and I want, that function recieve only one parameter...
So, now I understand, that likely to fail - use one parameter((
But it's archeticture very powerfull. And without this - it's impossible(
My library for easy saving Slib! Try this! Now you can encrypt your save!
- Drop of light LD#30
- OUTRANGE LD#31 (Sorry for my english. I learn it myself, and I don't have enough experience)
Probably missing your question but had an occasion where I wanted to monitor the values of some variables.
So, I wrote the following:
To use - add the following:
m = require 'monitor' -( to top of script )
m.watchBox() -( to love.draw() )
m.watch['something descriptive'] = variable_of_interest
Example:
m.watch['draw x'] = X
m.watch.y = Y
If the function in which the watched variable is accessed, the window is increased in size and the value displayed.
(In the demo provided, try clicking the mouse.)
For what's it worth.
To use debugger.watch() you need to know the actual name of the variable and from what I understood you wanted to know its name with the variable itself.
So by providing the variable
and its value, well that is impossible in lua, to monitor variables then all you need is a simple metatable to warn you everytime the variable is being accesed but I think that only works in table type variables.
Metatables are powerful tools in lua, you should totaly look into them.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping
Ref, I will watch monitor example. Ranguna259, thanks, I thought about it. And today I look into your debug. It's awesome.
Thanks for all!
Metatables.. Metatables.. Please give me some good links about this please.
My library for easy saving Slib! Try this! Now you can encrypt your save!
- Drop of light LD#30
- OUTRANGE LD#31 (Sorry for my english. I learn it myself, and I don't have enough experience)
Second link is awesome. Thanks. I know, what metatables are. But I miss practice...
My library for easy saving Slib! Try this! Now you can encrypt your save!
- Drop of light LD#30
- OUTRANGE LD#31 (Sorry for my english. I learn it myself, and I don't have enough experience)