self in pcall?

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]

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?

[lua]
pcall(table[“a”],table)
[/lua]

table.a is the same as table[“a”].

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.

Console:



] lua_run PrintTable( { pcall( table["a"] , table ) } )
> PrintTable( { pcall( table["a"] , table ) } )...
1    =    false
2    =    [@lua\includes\util.lua:35] bad argument #1 to 'pairs' (table expected, got nil)



:colbert:

[lua]

table = {}
function table:a()
PrintTable(self)
end
pcall(table[“a”], table)

[/lua]

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.

I just made a quick example and THEN I realised that.

Anyway thanks for the help my problem solved!