Is there a way to call a function with pcall that has self in it?
I mean:
[LUA]
table = {}
function table:a()
PrintTable( self )
end
pcall( table["a"] )
[/LUA]
[lua]pcall( table.a, table );[/lua]
[QUOTE=Nevec;25107142]pcall( table.a, table );[/QUOTE]
I already known that but I need the index to be a string. So it cant be: a.a it must be a["a"] .
I guess it can be done with CompileString. Or is it a too slow function for a Think hook?
[QUOTE=MDave;25107231]I already known that but I need the index to be a string. So it cant be: a.a it must be a["a"] .
I guess it can be done with CompileString. Or is it a too slow function for a Think hook?[/QUOTE]
[lua]
pcall(table["a"],table)
[/lua]
[I]table.a[/I] is the same as [I]table["a"][/I].
A function declaration like this:
[lua]function table:func( ... )[/lua]
Is the same as:
[lua]function table.func( self, ... )[/lua]
Passing the table as the second argument to pcall is what you want.
Don't, just don't declare an empty global table called "table". PLEASE. You're practically removing all table.* functions by doing that.
[lua]local tbl = {}
function tbl:a()
print( self )
end
pcall( tbl.a, tbl )
pcall( tbl["a"], tbl )[/lua]
Both work.
[QUOTE=raBBish;25107379]Don't, just don't declare an empty global table called "table". PLEASE. You're practically removing all table.* functions by doing that.
.[/QUOTE]
I just made a quick example and THEN I realised that.
Anyway thanks for the help my problem solved!
Sorry, you need to Log In to post a reply to this thread.