Leviathan  0.8.0.0
Leviathan game engine
Leviathan::JavaScriptHelper Class Reference

Class that collects various JavaScript functions that would bloat other parts. More...

#include <JavaScriptHelper.h>

Static Public Member Functions

static DLLEXPORT CefRefPtr< CefV8Value > ConvertNamedVariableListToJavaScriptValue (NamedVariableList *obj)
 Converts a NamedVariableList to CefV8Value. More...
 
static DLLEXPORT CefRefPtr< CefV8Value > ConvertVariableBlockToJavaScriptValue (VariableBlock *block)
 Converts a VariableBlock to CefV8Value. More...
 

Detailed Description

Class that collects various JavaScript functions that would bloat other parts.

Definition at line 13 of file JavaScriptHelper.h.

Member Function Documentation

◆ ConvertNamedVariableListToJavaScriptValue()

DLLEXPORT CefRefPtr< CefV8Value > Leviathan::JavaScriptHelper::ConvertNamedVariableListToJavaScriptValue ( NamedVariableList obj)
static

Converts a NamedVariableList to CefV8Value.

Precondition
The current thread must be inside V8 context (called from javascript or CefV8Context::Enter)

Definition at line 8 of file JavaScriptHelper.cpp.

10 {
11  // Check variable count //
12  if(obj->GetVariableCount() > 1) {
13  // We need to extract all objects //
14  size_t count = obj->GetVariableCount();
15 
16  // Create array //
17  CefRefPtr<CefV8Value> arrayval = CefV8Value::CreateArray((int)count);
18 
19  // Add all the objects //
20  for(int i = 0; i < (int)count; i++) {
21 
22  // Set the object //
23  arrayval->SetValue(
25  }
26 
27  return arrayval;
28 
29  } else if(obj->GetVariableCount() == 1) {
30  // Get the block //
31  VariableBlock* block = obj->GetValueDirect(0);
32 
34  }
35 
36  // No value //
37  return NULL;
38 }
Non-template class for working with all types of DataBlocks.
Definition: DataBlock.h:425
DLLEXPORT size_t GetVariableCount() const
Definition: NamedVars.cpp:733
static DLLEXPORT CefRefPtr< CefV8Value > ConvertVariableBlockToJavaScriptValue(VariableBlock *block)
Converts a VariableBlock to CefV8Value.
DLLEXPORT VariableBlock * GetValueDirect()
Definition: NamedVars.cpp:718

◆ ConvertVariableBlockToJavaScriptValue()

DLLEXPORT CefRefPtr< CefV8Value > Leviathan::JavaScriptHelper::ConvertVariableBlockToJavaScriptValue ( VariableBlock block)
static

Converts a VariableBlock to CefV8Value.

Precondition
The current thread must be inside V8 context (called from javascript or CefV8Context::Enter)

Definition at line 41 of file JavaScriptHelper.cpp.

42 {
43  // Switch on type //
44  switch(block->GetBlockConst()->Type) {
45  case DATABLOCK_TYPE_INT: {
46  return CefV8Value::CreateInt(block->ConvertAndReturnVariable<int>());
47  }
49  case DATABLOCK_TYPE_FLOAT: {
50  return CefV8Value::CreateDouble(block->ConvertAndReturnVariable<double>());
51  }
52  case DATABLOCK_TYPE_BOOL: {
53  return CefV8Value::CreateBool(block->ConvertAndReturnVariable<bool>());
54  }
56  return CefV8Value::CreateString(block->ConvertAndReturnVariable<std::wstring>());
57  }
59  case DATABLOCK_TYPE_STRING: {
60  return CefV8Value::CreateString(block->ConvertAndReturnVariable<std::string>());
61  }
62  default:
63  // Cannot be converted //
64  return NULL;
65  }
66 }
ConvertT ConvertAndReturnVariable() const
Definition: DataBlock.h:743
#define DATABLOCK_TYPE_INT
Definition: DataBlock.h:22
#define DATABLOCK_TYPE_WSTRING
Definition: DataBlock.h:25
#define DATABLOCK_TYPE_FLOAT
Definition: DataBlock.h:23
#define DATABLOCK_TYPE_STRING
Definition: DataBlock.h:26
#define DATABLOCK_TYPE_DOUBLE
Definition: DataBlock.h:28
const DataBlockAll * GetBlockConst() const
Definition: DataBlock.h:504
#define DATABLOCK_TYPE_BOOL
Definition: DataBlock.h:24
#define DATABLOCK_TYPE_CHAR
Definition: DataBlock.h:27

The documentation for this class was generated from the following files: