[DEV] better sample
This commit is contained in:
parent
e228ec0040
commit
d1180282ac
@ -38,6 +38,7 @@
|
|||||||
#include <lua/lauxlib.h>
|
#include <lua/lauxlib.h>
|
||||||
#include <ememory/memory.hpp>
|
#include <ememory/memory.hpp>
|
||||||
#include <etk/typeInfo.hpp>
|
#include <etk/typeInfo.hpp>
|
||||||
|
#include <etk/Allocator.hpp>
|
||||||
|
|
||||||
#define LUAW_POSTCTOR_KEY "__postctor"
|
#define LUAW_POSTCTOR_KEY "__postctor"
|
||||||
#define LUAW_EXTENDS_KEY "__extends"
|
#define LUAW_EXTENDS_KEY "__extends"
|
||||||
@ -246,7 +247,7 @@ void luaW_push(lua_State* _luaState,
|
|||||||
lua_pop(_luaState, 1); // ... id cache
|
lua_pop(_luaState, 1); // ... id cache
|
||||||
lua_insert(_luaState, -2); // ... cache id
|
lua_insert(_luaState, -2); // ... cache id
|
||||||
// placement new creation (need to initilaize the sructure:
|
// 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_pushvalue(_luaState, -1); // ... cache id obj obj
|
||||||
lua_insert(_luaState, -4); // ... obj cache id obj
|
lua_insert(_luaState, -4); // ... obj cache id obj
|
||||||
lua_settable(_luaState, -3); // ... obj cache
|
lua_settable(_luaState, -3); // ... obj cache
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#ifndef EXAMPLE_HPP_
|
#pragma once
|
||||||
#define EXAMPLE_HPP_
|
|
||||||
|
|
||||||
#include <etk/String.hpp>
|
#include <etk/String.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -19,4 +18,3 @@ class BankAccount {
|
|||||||
static float s_totalMoneyInBank;
|
static float s_totalMoneyInBank;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // EXAMPLE_HPP_
|
|
||||||
|
@ -2,21 +2,43 @@
|
|||||||
#include <lua/lua.h>
|
#include <lua/lua.h>
|
||||||
#include <lua/lualib.h>
|
#include <lua/lualib.h>
|
||||||
#include <lua/lauxlib.h>
|
#include <lua/lauxlib.h>
|
||||||
|
#include <test-debug/debug.hpp>
|
||||||
|
#include <etk/etk.hpp>
|
||||||
|
|
||||||
|
|
||||||
#include "LuaBankAccount.hpp"
|
#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[]) {
|
int main(int _argc, const char *_argv[]) {
|
||||||
if (_argc == 2) {
|
TEST_PRINT("START SAMPLE 1");
|
||||||
lua_State* L = luaL_newstate();
|
etk::init(_argc, _argv);
|
||||||
luaL_openlibs(L);
|
etk::String inputFileName;
|
||||||
luaopen_BankAccount(L);
|
for (int32_t iii=0; iii<_argc ; ++iii) {
|
||||||
if (luaL_dofile(L, _argv[1])) {
|
etk::String data = _argv[iii];
|
||||||
std::cout << lua_tostring(L, -1) << std::endl;
|
if ( data == "-h"
|
||||||
}
|
|| data == "--help") {
|
||||||
lua_close(L);
|
usage();
|
||||||
}
|
} else if (data.startWith("--file=") == true) {
|
||||||
return 0;
|
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;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#ifndef EXAMPLE_HPP_
|
#pragma once
|
||||||
#define EXAMPLE_HPP_
|
|
||||||
|
|
||||||
#include <etk/String.hpp>
|
#include <etk/String.hpp>
|
||||||
|
|
||||||
@ -57,4 +56,3 @@ class Example {
|
|||||||
int DoSomethingElse(float _f);
|
int DoSomethingElse(float _f);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
@ -1,5 +1,4 @@
|
|||||||
#ifndef LUA_CUSTOM_TYPES_H__
|
#pragma once
|
||||||
#define LUA_CUSTOM_TYPES_H__
|
|
||||||
|
|
||||||
#include <etk/String.hpp>
|
#include <etk/String.hpp>
|
||||||
|
|
||||||
@ -57,4 +56,3 @@ template<> struct luaU_Impl<Vector2D> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
@ -1,7 +1,5 @@
|
|||||||
#ifndef LUAEXAMPLE_HPP_
|
#pragma once
|
||||||
#define LUAEXAMPLE_HPP_
|
|
||||||
|
|
||||||
struct lua_State;
|
struct lua_State;
|
||||||
int luaopen_Example(lua_State* _L);
|
int luaopen_Example(lua_State* _L);
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#ifndef VECTOR2D_H_
|
#pragma once
|
||||||
#define VECTOR2D_H_
|
|
||||||
|
|
||||||
struct Vector2D {
|
struct Vector2D {
|
||||||
Vector2D(float x_ = 0.f, float y_ = 0.f) :
|
Vector2D(float x_ = 0.f, float y_ = 0.f) :
|
||||||
@ -11,4 +10,3 @@ struct Vector2D {
|
|||||||
float y;
|
float y;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
@ -3,18 +3,41 @@
|
|||||||
#include <lua/lua.h>
|
#include <lua/lua.h>
|
||||||
#include <lua/lualib.h>
|
#include <lua/lualib.h>
|
||||||
#include <lua/lauxlib.h>
|
#include <lua/lauxlib.h>
|
||||||
|
#include <test-debug/debug.hpp>
|
||||||
|
#include <etk/etk.hpp>
|
||||||
|
|
||||||
#include "LuaExample.hpp"
|
#include "LuaExample.hpp"
|
||||||
|
|
||||||
int main(int argc, const char *argv[]) {
|
static void usage() {
|
||||||
if (argc == 2) {
|
TEST_PRINT("Help:");
|
||||||
lua_State* L = luaL_newstate();
|
TEST_PRINT(" ./xxx [OPTIONS] ---");
|
||||||
luaL_openlibs(L);
|
TEST_PRINT(" --file=XXX File to execute");
|
||||||
luaopen_Example(L);
|
exit(0);
|
||||||
if (luaL_dofile(L, argv[1])) {
|
}
|
||||||
std::cout << lua_tostring(L, -1) << std::endl;
|
|
||||||
}
|
int main(int _argc, const char *_argv[]) {
|
||||||
lua_close(L);
|
TEST_PRINT("START SAMPLE 1");
|
||||||
}
|
etk::init(_argc, _argv);
|
||||||
return 0;
|
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;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user