当前版本:1.0.93
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
usage: tolua++ [options] input_file
Command line options are: -v : print version information. -o file : set output file; default is stdout. -H file : create include file. -n name : set package name; default is input file root name. -p : parse only. -P : parse and print structure information (for debug). -S : disable support for c++ strings. -1 : substract 1 to operator[] index (for compatibility with tolua5). -L file : run lua file (with dofile()) before doing anything. -D : disable automatic exporting of destructors for classes that have constructors (for compatibility with tolua5) -W : disable warnings for unsupported features (for compatibility with tolua5) -C : disable cleanup of included lua code (for easier debugging) -E value[=value] : add extra values to the luastate -t : export a list of types asociates with the C++ typeid name -q : don't print warnings to the console -h : print this message. Should the input file be omitted, stdin is assumed; in that case, the package name must be explicitly set. |
1
2 3 4 5 6 7 8 9 10 11 |
|
#define FALSE 0
#define TRUE 1 enum { POINT = 100, LINE, POLYGON } Object* createObejct ( int type); void drawObject (Object* obj, double red, double green, double blue); int isSelected (Object* obj); |
1
2 3 4 5 6 7 8 9 |
|
...
myLine = createObject(LINE) ... if isSelected(myLine) == TRUE then drawObject(myLine, 1. 0, 0. 0, 0. 0); else drawObject(myLine, 1. 0, 1. 0, 1. 0); end ... |
1
2 3 4 5 6 7 8 9 10 11 12 13 |
|
#define FALSE 0
#define TRUE 1 class Shape { void draw ( void); void draw ( double red, double green, double blue); int isSelected ( void); }; class Line : public Shape { Line ( double x1, double y1, double x2, double y2); ~Line ( void); }; |
1
2 3 4 5 6 7 8 9 10 11 |
|
...
myLine = Line:new ( 0, 0, 1, 1) ... if myLine:isSelected() == TRUE then myLine:draw( 1. 0, 0. 0, 0. 0) else myLine:draw() end ... myLine:delete() ... |
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
#pragma once
#include <string> class CTest { public: CTest( void); ~CTest( void); void SetA( int _a); int GetA(){ return a;} void SetB(std::string _b); std::string GetB(){ return b;} private: int a; std::string b; }; |
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
#include "Test.h"
CTest::CTest( void) { } CTest::~CTest( void) { } void CTest::SetA( int _a ) { a = _a; } void CTest::SetB( std::string _b ) { b = _b; } |
1
2 3 4 5 6 7 8 9 10 11 12 13 |
|
$#include "Test.h"
class CTest { CTest( void); ~CTest( void); void SetA( int _a); int GetA(); void SetB(std::string _b); std::string GetB(); }; |
1
|
|
tolua++ -o TestLua.cpp Test.pkg
|
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
#include "lua.hpp"
#pragma comment(lib, "lua5.1.lib") #pragma comment(lib, "tolua++.lib") int tolua_Test_open (lua_State* tolua_S); int main() { lua_State *L = luaL_newstate(); luaopen_base(L); tolua_Test_open(L); luaL_dofile(L, "testtest.lua"); lua_close(L); return 0; } |
1
2 3 4 5 6 |
|
mytest = CTest:new()
mytest:SetA( 5) mytest:SetB( "Hello") print(mytest:GetA()) print(mytest:GetB()) mytest:delete() |