diff --git a/luaWrapper/luaWrapper.hpp b/luaWrapper/luaWrapper.hpp index b6e221a..abab96b 100644 --- a/luaWrapper/luaWrapper.hpp +++ b/luaWrapper/luaWrapper.hpp @@ -38,6 +38,7 @@ #include #include #include +#include #define LUAW_POSTCTOR_KEY "__postctor" #define LUAW_EXTENDS_KEY "__extends" @@ -246,7 +247,7 @@ void luaW_push(lua_State* _luaState, lua_pop(_luaState, 1); // ... id cache lua_insert(_luaState, -2); // ... cache id // placement new creation (need to initilaize the sructure: - luaW_Userdata* ud = new (lua_newuserdata(_luaState, sizeof(luaW_Userdata))) luaW_Userdata(_obj, ETK_GET_TYPE_ID(LUAW_TYPE)); // ... cache id obj + luaW_Userdata* ud = new ((char*)lua_newuserdata(_luaState, sizeof(luaW_Userdata))) luaW_Userdata(_obj, ETK_GET_TYPE_ID(LUAW_TYPE)); // ... cache id obj lua_pushvalue(_luaState, -1); // ... cache id obj obj lua_insert(_luaState, -4); // ... obj cache id obj lua_settable(_luaState, -3); // ... obj cache diff --git a/sample/sample_1/BankAccount.hpp b/sample/sample_1/BankAccount.hpp index a5999c3..467de00 100644 --- a/sample/sample_1/BankAccount.hpp +++ b/sample/sample_1/BankAccount.hpp @@ -1,5 +1,4 @@ -#ifndef EXAMPLE_HPP_ -#define EXAMPLE_HPP_ +#pragma once #include #include @@ -19,4 +18,3 @@ class BankAccount { static float s_totalMoneyInBank; }; -#endif // EXAMPLE_HPP_ diff --git a/sample/sample_1/main.cpp b/sample/sample_1/main.cpp index ee603a4..abd901c 100644 --- a/sample/sample_1/main.cpp +++ b/sample/sample_1/main.cpp @@ -2,21 +2,43 @@ #include #include #include +#include +#include #include "LuaBankAccount.hpp" -using namespace std; +static void usage() { + TEST_PRINT("Help:"); + TEST_PRINT(" ./xxx [OPTIONS] ---"); + TEST_PRINT(" --file=XXX File to execute"); + exit(0); +} int main(int _argc, const char *_argv[]) { - if (_argc == 2) { - lua_State* L = luaL_newstate(); - luaL_openlibs(L); - luaopen_BankAccount(L); - if (luaL_dofile(L, _argv[1])) { - std::cout << lua_tostring(L, -1) << std::endl; - } - lua_close(L); - } - return 0; + TEST_PRINT("START SAMPLE 1"); + etk::init(_argc, _argv); + etk::String inputFileName; + for (int32_t iii=0; iii<_argc ; ++iii) { + etk::String data = _argv[iii]; + if ( data == "-h" + || data == "--help") { + usage(); + } else if (data.startWith("--file=") == true) { + inputFileName = etk::String(&_argv[iii][7]); + } + } + if (inputFileName.empty() == true) { + TEST_ERROR("missing file..."); + usage(); + } + lua_State* L = luaL_newstate(); + luaL_openlibs(L); + luaopen_BankAccount(L); + if (luaL_dofile(L, inputFileName.c_str())) { + TEST_PRINT(lua_tostring(L, -1)); + } + lua_close(L); + TEST_PRINT("END SAMPLE 1"); + return 0; } diff --git a/sample/sample_2/Example.hpp b/sample/sample_2/Example.hpp index 8fd0178..3386bcb 100644 --- a/sample/sample_2/Example.hpp +++ b/sample/sample_2/Example.hpp @@ -1,5 +1,4 @@ -#ifndef EXAMPLE_HPP_ -#define EXAMPLE_HPP_ +#pragma once #include @@ -57,4 +56,3 @@ class Example { int DoSomethingElse(float _f); }; -#endif \ No newline at end of file diff --git a/sample/sample_2/LuaCustomTypes.hpp b/sample/sample_2/LuaCustomTypes.hpp index 32b0a07..fce5af4 100644 --- a/sample/sample_2/LuaCustomTypes.hpp +++ b/sample/sample_2/LuaCustomTypes.hpp @@ -1,5 +1,4 @@ -#ifndef LUA_CUSTOM_TYPES_H__ -#define LUA_CUSTOM_TYPES_H__ +#pragma once #include @@ -57,4 +56,3 @@ template<> struct luaU_Impl { } }; -#endif \ No newline at end of file diff --git a/sample/sample_2/LuaExample.hpp b/sample/sample_2/LuaExample.hpp index 732f640..716ad6f 100644 --- a/sample/sample_2/LuaExample.hpp +++ b/sample/sample_2/LuaExample.hpp @@ -1,7 +1,5 @@ -#ifndef LUAEXAMPLE_HPP_ -#define LUAEXAMPLE_HPP_ +#pragma once struct lua_State; int luaopen_Example(lua_State* _L); -#endif diff --git a/sample/sample_2/Vector2D.hpp b/sample/sample_2/Vector2D.hpp index 53ee6b2..5fac5a1 100644 --- a/sample/sample_2/Vector2D.hpp +++ b/sample/sample_2/Vector2D.hpp @@ -1,5 +1,4 @@ -#ifndef VECTOR2D_H_ -#define VECTOR2D_H_ +#pragma once struct Vector2D { Vector2D(float x_ = 0.f, float y_ = 0.f) : @@ -11,4 +10,3 @@ struct Vector2D { float y; }; -#endif \ No newline at end of file diff --git a/sample/sample_2/main.cpp b/sample/sample_2/main.cpp index e388055..d252cea 100644 --- a/sample/sample_2/main.cpp +++ b/sample/sample_2/main.cpp @@ -3,18 +3,41 @@ #include #include #include +#include +#include #include "LuaExample.hpp" -int main(int argc, const char *argv[]) { - if (argc == 2) { - lua_State* L = luaL_newstate(); - luaL_openlibs(L); - luaopen_Example(L); - if (luaL_dofile(L, argv[1])) { - std::cout << lua_tostring(L, -1) << std::endl; - } - lua_close(L); - } - return 0; +static void usage() { + TEST_PRINT("Help:"); + TEST_PRINT(" ./xxx [OPTIONS] ---"); + TEST_PRINT(" --file=XXX File to execute"); + exit(0); +} + +int main(int _argc, const char *_argv[]) { + TEST_PRINT("START SAMPLE 1"); + etk::init(_argc, _argv); + etk::String inputFileName; + for (int32_t iii=0; iii<_argc ; ++iii) { + etk::String data = _argv[iii]; + if ( data == "-h" + || data == "--help") { + usage(); + } else if (data.startWith("--file=") == true) { + inputFileName = etk::String(&_argv[iii][7]); + } + } + if (inputFileName.empty() == true) { + TEST_ERROR("missing file..."); + usage(); + } + lua_State* L = luaL_newstate(); + luaL_openlibs(L); + luaopen_Example(L); + if (luaL_dofile(L, inputFileName.c_str())) { + TEST_PRINT(lua_tostring(L, -1)); + } + lua_close(L); + return 0; }