C++ Builder编译Lua 5.1静态库以及使用的方法
(2013-04-08 09:57:28)
网上有个英文版本的,直接Copy,Mark一下
This
shortly manual how work with lua script engine from Borland C++
6.
第一步下载源代码:
First download sources: http://www./ftp/lua-5.1.tar.gz
Next:
- start
BCB6->File->New->Other->Library
- Add to Project->C File
(*.c)->Select all .c files from unpacked sources and
and click open
- Save All
- Build
- Go to directory with your saved project
- copy new .lib file to $(BCB)/lib
- go to $(BCB)/include and create file lua.hpp with this
content:
//
lua.hpp
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
- copy lua.h,lualib.h,luaxlib.h,luaconf.h to
$(BCB)/include
Create test program:
-
File->New->Application
- Add to Project->Library file
(.lib)->YourCompiledLibFileWithLua.lib
- Drop button to form
- edit header project:
//---------------------------------------------------------------------------
#ifndef LuaMainH
#define LuaMainH
//---------------------------------------------------------------------------
#include
#include
#include
#include
#include
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
void __fastcall Button1Click(TObject
*Sender);
void __fastcall FormClose(TObject *Sender,
TCloseAction &Action);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
int l_ShowMessage( lua_State* L );
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
- edit code project
//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include "LuaMain.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
lua_State *L;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
L = lua_open();
luaopen_base(L);
luaopen_table(L);
luaopen_string(L);
luaopen_math(L);
luaopen_debug(L);
lua_register(L,"ShowMessage",l_ShowMessage);
}
//---------------------------------------------------------------------------
int l_ShowMessage( lua_State* L )
{
ShowMessage(AnsiString( lua_tostring(L, -1) ));
lua_pushnumber( L, 0 );
return 1;
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int ret = luaL_loadfile(L,"Hello.lua");
if ( ret == 0 ) {
lua_pcall(L, 0, LUA_MULTRET, 0);//execute
Hello.lua
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction
&Action)
{
lua_close(L);
}
//---------------------------------------------------------------------------
- Save All
- create file Hello.lua inside project directory with this
content
ShowMessage("I
say hello to you");
- Build project
- Run Project
- Push the button.
That\'s allC++ Builder编译Lua 5.1静态库以及使用的方法
(2013-04-08 09:57:28)
网上有个英文版本的,直接Copy,Mark一下
This
shortly manual how work with lua script engine from Borland C++
6.
第一步下载源代码:
First download sources: http://www./ftp/lua-5.1.tar.gz
Next:
- start
BCB6->File->New->Other->Library
- Add to Project->C File
(*.c)->Select all .c files from unpacked sources and
and click open
- Save All
- Build
- Go to directory with your saved project
- copy new .lib file to $(BCB)/lib
- go to $(BCB)/include and create file lua.hpp with this
content:
//
lua.hpp
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
- copy lua.h,lualib.h,luaxlib.h,luaconf.h to
$(BCB)/include
Create test program:
-
File->New->Application
- Add to Project->Library file
(.lib)->YourCompiledLibFileWithLua.lib
- Drop button to form
- edit header project:
//---------------------------------------------------------------------------
#ifndef LuaMainH
#define LuaMainH
//---------------------------------------------------------------------------
#include
#include
#include
#include
#include
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
void __fastcall Button1Click(TObject
*Sender);
void __fastcall FormClose(TObject *Sender,
TCloseAction &Action);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
int l_ShowMessage( lua_State* L );
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
- edit code project
//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include "LuaMain.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
lua_State *L;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
L = lua_open();
luaopen_base(L);
luaopen_table(L);
luaopen_string(L);
luaopen_math(L);
luaopen_debug(L);
lua_register(L,"ShowMessage",l_ShowMessage);
}
//---------------------------------------------------------------------------
int l_ShowMessage( lua_State* L )
{
ShowMessage(AnsiString( lua_tostring(L, -1) ));
lua_pushnumber( L, 0 );
return 1;
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int ret = luaL_loadfile(L,"Hello.lua");
if ( ret == 0 ) {
lua_pcall(L, 0, LUA_MULTRET, 0);//execute
Hello.lua
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction
&Action)
{
lua_close(L);
}
//---------------------------------------------------------------------------
- Save All
- create file Hello.lua inside project directory with this
content
ShowMessage("I
say hello to you");
- Build project
- Run Project
- Push the button.
That\'s all
|