PDA

View Full Version : lua script embedding



noeska
23-05-2004, 10:37 PM
Is anyone using lua together with delphi here? How can lua access delphi variables? Thanks for your answer in advance!

noeska
24-05-2004, 11:36 AM
meanwhile i discovered that setting (exporting) a global var to lua goes like:



//set global var A with value 10
//this pushes the globals table of state L
lua_pushvalue(L, LUA_GLOBALSINDEX);
//this sets a key in the globals table of L
lua_pushstring&#40;L, 'a'&#41;; //Be aware lua vars are case sensitive!! a<>A
lua_pushnumber&#40;L, 100&#41;;
lua_settable&#40;L, LUA_GLOBALSINDEX&#41;; // global noot = "mies"
//end set


And reading a global var from lua to delphi goes like:



//read global var from lua
//this pushes the globals table of state L
lua_pushvalue&#40;L, LUA_GLOBALSINDEX&#41;;
lua_pushstring&#40;L, 'result'&#41;;
lua_gettable&#40;L, LUA_GLOBALSINDEX&#41;; // global aap
writeln&#40;'Delphi&#58; '+floattostr&#40;lua_tonumber&#40;L, -1&#41;&#41;&#41;; //why -1?
//end read


This should get me going.

But on looking on the lua maillist archive i read it should be possible to use c++ classes from within lua? Does this also go for delphi objects? How?