lua-users home
lua-l archive

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


Hi,

I?ve have been experimenting with the notion of binding data from C/C++ to
LUA on a binary executable level.  This would allow LUA scripts to access
C/C++ data without having to maintain any binding code in the host
program. Since I?m mostly familiar with MSVC, I started with it on
Windows. MSVC.net 2002 comes with the DIA SDK. This allows you full access
to the symbol database, or better known as PDB files.

The PDB file contains the debug information for a program including all
memory addresses, type information for all variables, classes, functions,
and enumerations.  Well basically any information you normally access in
the debugger is stored there.  This gives us a blueprint of the entire
program in memory and gives you everything you need to safely manipulate
your program from LUA without writing any extra code or setup.

I?d like to report that I?ve got a basic example working - the features
are currently very minimal. It only supports basic data types on the
global scope.  Obviously this is not complete, and very few people would
want to ship out software with your symbol tables, but certainly this does
open the door to many different options.  I plan to expand it to support
functions and more complex user data types.

You can grab a link to the example program here.

http://www.fscnation.com/~glo/CP/CPB.zip - Check out test.lua

I would love some feedback if you might find something like this useful.
(glo@fscnation.com) At least from the quickly and dirty perspective it is
nice to simply link in a library, hit the compile button, and magically
have every variable, function and class accessible from LUA with just a
few lines of code.

Thomas

----------
note: You may need to first register msdia71.dll .  On the command prompt
type "regsvr32.exe msdia71.dll" if the example exe doesn?t work


For example:

Let?s say you have the following variables in your program.

int cp_Int         = 111;
short cp_Short     = 222;

In your LUA script you can do the following

CP_OpenPDB ("CPTest");
CP_BindVariable("cp_*");  -- Binds all variables that starts with ?cp_?
CP_ClosePDB();

And do the following in LUA

CPTest.cp_Int = -133

Your variable in the C Program will now be updated.