lua-users home
lua-l archive

Passing arrays from C++ to LUA

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello,
I like to pass some C++ arrays to LUA. The other way from LUA to C++ is already done. I show you in pseudo language what I need:
LUA:
> a = getArray ()
C++:
fill a array with many numbers and return it in the getArray() function
LUA:
> print (a[1])
4
> print (a[2])
5
> print (a[3])
6
....
My problem is I don't know how to do this in C++. Perhaps someone could help and tell me how this works. What I tried last was:
C++:
 lua_newtable (L);
 lua_settable (L,1);
 
 lua_Integer n = 6;
 lua_pushinteger (L, n);
LUA:
	tc=TestClass:new()
	a=tc:testX()
	print (a[1])
	[string "print (a[1])"]:1: attempt to index global 'a' (a nil value)
regards
	Andreas Volz
-- 
Dipl.-Inf. (FH) Andreas Volz, ES1
Elektrobit 
Phone: +49 (9131) 7701 167, mailto:Andreas.Volz@elektrobit.com
Fax: +49 (9131) 7701 333, http://www.elektrobit.com
Elektrobit Automotive GmbH, Am Wolfsmantel 46, 91058 Erlangen, Germany
Managing Director Otto Fößel
Register Court Fürth HRB 4886
----------------------------------------------------------------
Please note: This e-mail may contain confidential information
intended solely for the addressee. If you have received this
e-mail in error, please do not disclose it to anyone, notify
the sender promptly, and delete the message from your system.
Thank you.

AltStyle によって変換されたページ (->オリジナル) /