Re: raw pointer in lua
"Nigel Atkinson" <[email protected]> Tue, 10 Jan 2012 13:42:09 +1100
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
On Mon, January 9, 2012 11:04 pm, ���� wrote:
> code(C++):
>
luabind::object_cast<bool>(m_luaObject["SetAttribute"](m_luaObject,
this,
> strName, strValue));
>
> m_luaObject is luabind::object type. I call it's SetAttribute
method��and
> pass the second parameter "this" pointer. I had register
the class of
> "this" in the lua.
> Now, I want to call some method through "this" pointer in
the lua. How can
> I do it?
>
> code(LUA):
> function TextButton:SetAttribute(object, name, value)
> object.InternalFindUIObject("caption") -- "this"
pointer, how can
> I user here?
> end
You should be able to
call:
this:method()
Depending on
what you have registered for the class that 'this' is an instance
of.
I've attached a small
example.
Nigel
>
>
> Thanks!
>
------------------------------------------------------------------------------
> Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a
complex
> infrastructure or vast IT resources to deliver seamless, secure
access to
> virtual desktops. With this all-in-one solution, easily deploy
virtual
> desktops for less than the cost of PCs and save 60% on VDI
infrastructure
> costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
> _______________________________________________
> luabind-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create
new or port existing apps to sell to consumers worldwide. Explore the
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user
this.cpp
(text/x-c++src, 1.1 KB)
#include <luabind/luabind.hpp>
#include <iostream>
#include <lua.hpp>
using namespace luabind;
using namespace std;
class Item
{
public:
string name;
Item( string n ) { name = n; }
void printString() { cout << "Item: " << name << endl; }
};
int main()
{
lua_State* L = lua_open();
luaL_openlibs( L );
luabind::open(L);
module(L)
[
class_<Item>( "Item" )
.def( constructor<string>() )
.def( "printString", &Item::printString )
];
const char *script =
"class 'zing'\n"
"function zing:splat( object )\n"
" object:printString()\n"
"end\n"
"function zing:__init()\n"
" print 'Created a zing'\n"
"end\n"
"myzing = zing()\n";
if( luaL_dostring( L, script ) )
cout << lua_tostring( L, -1 ) << endl;
Item item( "An item" );
// This scope is so 'myzing' goes out of scope and destructs
// before lua_close is called.
// Otherwise you get trouble.
{
object myzing = globals(L)["zing"];
myzing["splat"]( myzing, item );
}
lua_close( L );
return 0;
}