PDA

View Full Version : Delphi plugin examples



Rob H
February 15th, 2005, 11:58 AM
Which of the plugins are implemented in Delphi? I only found two and the Generic_SerialIR plugin isn't found.

Are there any Delphi examples of adding commands to Lua? That's what I want to try doing.

birty
February 15th, 2005, 01:08 PM
my media player plugin is written in delphi, it doesnt use any lua though

Rob H
February 15th, 2005, 01:16 PM
Thanks, I'll take a look.

Can't have too many examples.

Rob H
February 15th, 2005, 05:50 PM
Ron - any suggestions for implementing a plugin in Delphi that extends Lua?

Rob H
February 20th, 2005, 08:17 AM
I'm struggling a bit with this plugin.

I just don't quite understand what I need to do with userdata and tags in order to get my objects garbage collected.

I've had a look at MarkF's plugins, but I find C++ (and C) to be as clear as mud most of the time.

Is this documented properly anywhere?

Promixis
February 20th, 2005, 12:42 PM
Rob, Ron might have some delphi code that does this. I have some C code using metatables and the gc. Do you want it?

Rob H
February 20th, 2005, 12:49 PM
This is currently for Girder 3.3, so it needs to use settagmethod etc. but any additional sources would be welcome.

birty
February 20th, 2005, 12:56 PM
i can help port from c to delphi if you need me to

Rob H
February 20th, 2005, 01:00 PM
Thanks. I'm mostly okay reading C as long as the declarations don't get too complex. I have a tame C++ programmer on the end of a phone line if I need a bit of code explaining.

But I might take you up on that if I get stuck.

It's more a question of understanding the mechanisms involved in interfacing with Lua.

Rob H
February 20th, 2005, 01:17 PM
Rob, Ron might have some delphi code that does this.

Ron? Is Mike right?

Promixis
February 20th, 2005, 01:57 PM
I was thinking lua 5/g4 - will ask him about g3.3

Ron
February 20th, 2005, 09:33 PM
Sorry I have nothing very fancy in G3.3 that uses Garbage collection. Lua5/G4 I could help though.

Rob H
February 21st, 2005, 02:18 AM
Thanks Ron. The G4 examples would probably help, after all I'lll have to port the plugin sometime.

Rob H
February 23rd, 2005, 02:05 PM
Gentle reminder.

Ron
February 23rd, 2005, 02:06 PM
:-)

Ron
February 23rd, 2005, 02:16 PM
Okay I have been looking through the G4 code but there is nothing that I can give out in full :( However I am more then happy to help with specific questions. First chapter 28 is a great resource for getting into the metatable business.

http://www.lua.org/pil/28.html

Then to register a function that run on garbage collection do this:




// CreateRegistry&#40;<rootname>, <keyname>&#41;
static int CreateRegistry&#40;lua_State * L&#41;
&#123;

pRegistry registry; // this is a pointer to a structure Make you own for this.

// I REMOVED SOME CODE HERE.


registry = &#40;pRegistry&#41; lua_newuserdata&#40;L, sizeof&#40;sRegistry&#41;&#41;;

// set the fields...
registry->Key = key;

// push it into Lua.

luaL_getmetatable&#40;L,REGISTRYMETATABLENAME&#41;;
lua_setmetatable&#40;L,-2&#41;;
lua_pushnil&#40;L&#41;;
return 2;
&#125;



// checks if there is a Timer Object on the stack
static pRegistry checkregistry &#40;lua_State *L&#41;
&#123;

void *ud = luaL_checkudata&#40;L, 1, REGISTRYMETATABLENAME&#41;;
luaL_argcheck&#40;L, ud != NULL, 1, "`Registry object' expected"&#41;;
return &#40;pRegistry&#41;ud;

&#125;
// Garbage Collection, automatically called by lua when the Time Is Right &#40;c&#41;.
static int registry_gc &#40;lua_State *L&#41;
&#123;

pRegistry registry = checkregistry&#40;L&#41;;
Cleanup&#40;registry&#41;; // make you own
return 0;
&#125;

static const struct luaL_reg registrylib_f &#91;&#93; = &#123;
&#123;"CreateRegistry", CreateRegistry&#125;,
&#123;NULL, NULL&#125;
&#125;;

static const struct luaL_reg registrylib_m &#91;&#93; = &#123;
&#123;MANY MORE ENTRIES HERE&#125;
&#123;"__gc", registry_gc&#125;,
&#123;NULL, NULL&#125;
&#125;;

int lua_openregistry &#40;lua_State *L&#41;
&#123;
luaL_newmetatable&#40;L, REGISTRYMETATABLENAME&#41;;

lua_pushstring&#40;L, "__index"&#41;;
lua_pushvalue&#40;L, -2&#41;; /* pushes the metatable */
lua_settable&#40;L, -3&#41;; /* metatable.__index = metatable */

luaL_openlib&#40;L, NULL, registrylib_m, 0&#41;;

luaL_openlib&#40;L, "win", registrylib_f, 0&#41;;

lua_pop&#40;L,2&#41;;

return 1;
&#125;

Rob H
February 23rd, 2005, 02:40 PM
Thanks Ron.

I'll study that in more detail tomorrow.

No Delphi examples I take it?

Ron
February 23rd, 2005, 02:43 PM
Sorry no Delphi. It's pretty easy to translate though.

shura_k
February 24th, 2005, 09:11 AM
You can see BigNumber plugin for Deplhi and LUA example.
And Girder Delphi Header file.

Rob H
February 24th, 2005, 09:51 AM
Brilliant, thanks - I'll take a look