//------- Lua --------
//--test.lua
//LuaC_MessageBox( "Last is ShowMessage! This is real MessageBox!");
//------------ test.cpp ----------------
//================================================================================================================
// Lua Test Object
// C++ Source lua_test.cpp
//================================================================================================================
//================================================================================================================
// Include Files
//================================================================================================================
extern "C"
{
#include "D:\\My Documents\\Visual Studio 2005\\Projects\\lua\\lua\\lua.h"
#include "D:\\My Documents\\Visual Studio 2005\\Projects\\lua\\lua\\lualib.h"
#include "D:\\My Documents\\Visual Studio 2005\\Projects\\lua\\lua\\lauxlib.h"
}
#include <windows.h>
#include <stdio.h>
#include <string>
using namespace std;
//================================================================================================================
// Libraries
//================================================================================================================
#pragma comment( lib ,"D:\\My Documents\\Visual Studio 2005\\Projects\\lua\\release\\lua.lib")
//================================================================================================================
// Global Variables
//================================================================================================================
lua_State *L;
//================================================================================================================
// Lua Functions
//================================================================================================================
double f( double x, double y )
{
double ret;
lua_getglobal( L, "f");
lua_pushnumber( L,x);
lua_pushnumber( L,y);
lua_call( L, 2, 1);
//lua_pcall( L, 2, 1, 0);
ret = lua_tonumber( L, -1);
//lua_pop( L, 1);
return ret;
}
//================================================================================================================
// C/C++ Functions
//================================================================================================================
int LuaC_MessageBox( lua_State *L)
{
char Message[256] = "";
int i;
//
int n = lua_gettop(L);
//
for ( i = 1, j = 0; i <= n ; i++)
{
if ( lua_isstring( L, i))
strcpy( Message, lua_tostring( L, i));
}
//
MessageBox( NULL, Message, "Lua Test", MB_OK );
//
//
return 0;
}
//================================================================================================================
// Main Functions
//================================================================================================================
int main( void)
{
int error;
L = lua_open();
luaopen_base(L);
luaL_openlibs(L);
// C/C++
lua_register( L, "LuaC_MessageBox", LuaC_MessageBox);
// load the script
//
if ( (error = luaL_dofile(L, "test.lua")) != 0)
{
MessageBox( NULL, " : !", "Lua Test", MB_OK );
return 0;
}
getchar();
lua_close( L);
return 1;
}