|
|
@ -6,6 +6,10 @@
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include "ScriptFunction.hpp"
|
|
|
|
#include "ScriptFunction.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _WIN32 // temporally disabled
|
|
|
|
|
|
|
|
#include <call.hpp>
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined (ENABLE_LUA)
|
|
|
|
#if defined (ENABLE_LUA)
|
|
|
|
#include "LangLua/LangLua.hpp"
|
|
|
|
#include "LangLua/LangLua.hpp"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
@ -120,105 +124,42 @@ boost::any ScriptFunction::Call(const vector<boost::any> &args)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw runtime_error("Native Call: native calls does not supported yet");
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
#ifdef ARCH_X86
|
|
|
|
|
|
|
|
// cdecl convention
|
|
|
|
|
|
|
|
string::iterator it;
|
|
|
|
string::iterator it;
|
|
|
|
vector<boost::any>::const_iterator it2;
|
|
|
|
vector<boost::any>::const_iterator it2;
|
|
|
|
vector<unsigned int> data;
|
|
|
|
vector<intptr_t> data;
|
|
|
|
|
|
|
|
CallArgs callArgs;
|
|
|
|
|
|
|
|
|
|
|
|
for (it = def.begin(), it2 = args.begin(); it != def.end(); ++it, ++it2)
|
|
|
|
for (it = def.begin(), it2 = args.begin(); it != def.end(); ++it, ++it2)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
switch (*it)
|
|
|
|
switch (*it)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case 'i':
|
|
|
|
case 'i':
|
|
|
|
{
|
|
|
|
callArgs.push_integer(boost::any_cast<unsigned int>(*it2));
|
|
|
|
unsigned int value = boost::any_cast<unsigned int>(*it2);
|
|
|
|
|
|
|
|
data.push_back(value);
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'q':
|
|
|
|
case 'q':
|
|
|
|
{
|
|
|
|
callArgs.push_integer(boost::any_cast<signed int>(*it2));
|
|
|
|
unsigned int value = boost::any_cast<signed int>(*it2);
|
|
|
|
|
|
|
|
data.push_back(value);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'l':
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
unsigned long long value = boost::any_cast<unsigned long long>(*it2);
|
|
|
|
|
|
|
|
data.push_back(*reinterpret_cast<unsigned int *>(&value));
|
|
|
|
|
|
|
|
data.push_back(*reinterpret_cast<unsigned int *>((unsigned) &value + 4));
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'w':
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
signed long long value = boost::any_cast<signed long long>(*it2);
|
|
|
|
|
|
|
|
data.push_back(*reinterpret_cast<unsigned int *>(&value));
|
|
|
|
|
|
|
|
data.push_back(*reinterpret_cast<unsigned int *>((unsigned) &value + 4));
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'f':
|
|
|
|
case 'f':
|
|
|
|
{
|
|
|
|
callArgs.push_double(boost::any_cast<double>(*it2));
|
|
|
|
double value = boost::any_cast<double>(*it2);
|
|
|
|
|
|
|
|
data.push_back(*reinterpret_cast<unsigned int *>(&value));
|
|
|
|
|
|
|
|
data.push_back(*reinterpret_cast<unsigned int *>((unsigned) &value + 4));
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'd':
|
|
|
|
|
|
|
|
callArgs.push_double(boost::any_cast<double*>(*it2));
|
|
|
|
case 'p':
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
void *value = boost::any_cast<void *>(*it2);
|
|
|
|
|
|
|
|
data.push_back(reinterpret_cast<unsigned int>(value));
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
case 's':
|
|
|
|
{
|
|
|
|
callArgs.push_stringPtr(boost::any_cast<const char *>(*it2));
|
|
|
|
const string *value = boost::any_cast<string>(&*it2);
|
|
|
|
break;
|
|
|
|
data.push_back(reinterpret_cast<unsigned int>(value->c_str()));
|
|
|
|
case 'v':
|
|
|
|
|
|
|
|
result = boost::any();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
throw runtime_error("C++ call: Unknown argument identifier " + *it);
|
|
|
|
throw runtime_error("C++ call: Unknown argument identifier " + *it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef _WIN32 // temporally disabled
|
|
|
|
unsigned int result_low;
|
|
|
|
Func f = reinterpret_cast<Func>(fCpp);
|
|
|
|
unsigned int result_high;
|
|
|
|
result = ::Call(f, callArgs);
|
|
|
|
unsigned int *source = &data[0];
|
|
|
|
|
|
|
|
unsigned int size = data.size() * 4;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
asm(
|
|
|
|
|
|
|
|
"MOV EDI,ESP\n"
|
|
|
|
|
|
|
|
"SUB EDI,%3\n" // allocate memory in stack.
|
|
|
|
|
|
|
|
"MOV ESI,%4\n" // move ptr of source to ESI.
|
|
|
|
|
|
|
|
"MOV ECX,%3\n" // length of data.
|
|
|
|
|
|
|
|
"PUSH DS\n" // move DS
|
|
|
|
|
|
|
|
"POP ES\n" // to ES.
|
|
|
|
|
|
|
|
"CLD\n" // clear direction flag.
|
|
|
|
|
|
|
|
"REP MOVSB\n" // Move bytes at address DS:ESI to address ES:EDI (move to stack).
|
|
|
|
|
|
|
|
"MOV ESI,ESP\n" // stack pointer.
|
|
|
|
|
|
|
|
"SUB ESP,%3\n"
|
|
|
|
|
|
|
|
"CALL %2\n"
|
|
|
|
|
|
|
|
"MOV ESP,ESI\n"
|
|
|
|
|
|
|
|
"MOV %0,EAX\n" // move low result from eax
|
|
|
|
|
|
|
|
"MOV %1,EDX\n" // move high result from edx
|
|
|
|
|
|
|
|
: "=m"(result_low), "=m"(result_high)
|
|
|
|
|
|
|
|
: "m"(fCpp) //2, "m"(size) //3, "m"(source) //4
|
|
|
|
|
|
|
|
: "eax", "edx", "ecx", "esi", "edi", "cc"
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*reinterpret_cast<unsigned int *>(&result) = result_low;
|
|
|
|
|
|
|
|
*reinterpret_cast<unsigned int *>(((unsigned) &result) + 4) = result_high;
|
|
|
|
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
throw runtime_error("x64 Not supported yet (builtin timers and [Call/Make]Public");
|
|
|
|
throw runtime_error("C++ call: Windows not supported yet.")
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|