lua-users home
lua-l archive

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


I'm a Delphi user too and wanted to use Lua for scripting in our game
projects. I like things to be simple yet elegant. What I ended up coding was
an add-on for our game engine (GameVision) called ScriptVision. Features

* Based on Lua 5.0.2
* Easy, robust API interface
* Bindings for Delphi & C/C++
* Works with any language that supports standard DLLs
* Use the stdcall calling convention for maximum compatibility
* Support for:
  * error handling
  * call native/script routines and pass/get params
  * structs in both script/code
  * globals in both script/code
  * many stack oriented routines
  * run script from memory buffer or from dist
  * debug interface
* Much more

You can download it here: (~260KB)

Any feedback and suggestions would be most appreciated. I can also supply
C/C++ bindings if there is an interest. I have a script editor that is in
the works (syntax highlighting, debugging, etc).

This is a small example of how you can use it with Delphi:


{ === Script Functions ================================================== }
procedure OnError(aErrMsg, aSource, aFunc: SV_String; aLine: SV_Integer);
stdcall; var
  s: string;
  s := Format('%s - %s:%d (%s)', [aErrMsg, aSource, aLine, aFunc]);
  MessageBox(0, PChar(s), 'Script Error', MB_OK);

function svf_MessageBox(p: SV_Pointer): SV_Integer; stdcall; var
  aCaption: string;
  aMsg: string;
  // get the message string
  aMsg := SV_PopString;

  // et the caption string
  aCaption := SV_PopString;

  // display message box
  MessageBox(0, PChar(aMsg), PChar(aCaption), MB_OK);

  // return zero since we are not returning any results
  Result := 0;


  s: string;

{ === Main ============================================================== }
  // let define an error handler

  // register functions
  SV_RegisterFunction('MessageBox', svf_MessageBox);

  // let call the script function directly
  SV_SetStringParam('Direct call.');
  SV_CallFunction('MessageBox', SV_Nil);

  // lets call the script function from a buffer
  s := 'MessageBox(''ScriptVision'', ''Call from a buffer.'')';
  SV_LoadFromBuffer(PChar(s), Length(s), 'buff');

  // load run a script from a file

  // call a routine in loaded script
  SV_CallFunction('ReturnResult', SV_Str);
  s := SV_GetStringReturn;
  MessageBox(0, PChar(s), 'Return Result', MB_OK);

  SV_CallFunction('CoolEasy', SV_Nil);


function CoolEasy()
  MessageBox('With ScriptVision', 'Lua scripting is easy and cool.'); end

function ReturnResult()
  return "I've returned a string";

MessageBox('ScriptVision', 'Running from a file on disk.');

I hope that it can be of use to someone.

Best regards,

Jarrod Davis,
Owner/Lead Developer
Big Daddy Games

-----Original Message-----
[] On Behalf Of Stijn De Saeger
Sent: Friday, March 04, 2005 12:29 AM
Subject: Attn : Ron Bessems and other Delphi users


I'm currently shopping around for an embeddable scripting language to
include in
a delphi application. There seem to be many pascal scripting
components in delphi, but if possible I would like to use something I
can also use stand-alone (for those occasions where a full-fledged
delphi app would be over-kill).
I like the language concept of lua a lot, it is elegant and
straightforward, it would be excellent for the job, language-wise.
However, I am not a C programmer and I find it hard to get a feel for
what is possible when it comes to linking lua to other languages than
I would be very interested in any information you have on integrating
lua with Delphi. How do the lua environment and the delphi environment
integrate? What are the limitations? Is a two-way binding doable /
elegant / stable / hackish ?
In short, I would very much like to hear whatever information, war
stories, source examples you want to share, urls to other information
that helped you out with the problems you had implementing, the lot.

Thanks a bunch.