aboutsummaryrefslogtreecommitdiff
path: root/src/script/graphics/luaopen_JSL.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-05-17 19:12:18 +0800
committerchai <chaifix@163.com>2018-05-17 19:12:18 +0800
commit9edf2ba9fe8524976d2f298767fff0149e8c0d41 (patch)
tree38d74676a57de508a40ac581286255c2a18dce12 /src/script/graphics/luaopen_JSL.cpp
parent70cdd89e887641b7423e5d4d05928d14ee014aba (diff)
change file tree
Diffstat (limited to 'src/script/graphics/luaopen_JSL.cpp')
-rw-r--r--src/script/graphics/luaopen_JSL.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/script/graphics/luaopen_JSL.cpp b/src/script/graphics/luaopen_JSL.cpp
new file mode 100644
index 0000000..c7b4e5e
--- /dev/null
+++ b/src/script/graphics/luaopen_JSL.cpp
@@ -0,0 +1,88 @@
+#include "3rdparty/luax/luax.h"
+#include "libjin/render/jsl.h"
+#include "../luaopen_types.h"
+namespace jin
+{
+namespace lua
+{
+
+ using namespace render;
+
+ static inline JSLProgram* checkJSLProgram(lua_State* L)
+ {
+ return (JSLProgram*)luax_checktype(L, 1, TYPE_JSL);
+ }
+
+ static enum VARIABLE_TYPE
+ {
+ INVALID = 0,
+ NUMBER ,
+ IMAGE ,
+ TEXEL
+ };
+
+ static VARIABLE_TYPE strtotype(const char* str)
+ {
+ std::string s = std::string(str);
+ if (s == "number") return NUMBER;
+ else if (s == "Image") return IMAGE;
+ else if (s == "Texel") return TEXEL;
+ else return INVALID;
+ }
+
+ /**
+ * Use send function send variables to JSL program.
+ */
+ static int l_send(lua_State* L)
+ {
+ JSLProgram* jsl = checkJSLProgram(L);
+ // number Image Texel
+ const char* typestr = luax_checkstring(L, 2);
+ // variable name
+ const char* variable = luax_checkstring(L, 3);
+ if (typestr != nullptr)
+ {
+ int type = strtotype(typestr);
+ switch (type)
+ {
+ case NUMBER:
+ {
+ float number = luax_checknumber(L, 4);
+ jsl->sendFloat(variable, number);
+ break;
+ }
+ case IMAGE:
+ {
+ Image* img = (Image*)luax_checktype(L, 4, TYPE_IMAGE);
+ jsl->sendImage(variable, img);
+ break;
+ }
+ case TEXEL:
+ break;
+ }
+ }
+ return 1;
+ }
+
+ static int l_gc(lua_State* L)
+ {
+
+ return 0;
+ }
+
+ static const luaL_Reg f[] = {
+ {"send", l_send},
+ {"__gc", l_gc},
+ {0, 0}
+ };
+
+ /**
+ * JSL program
+ */
+ int luaopen_JSL(lua_State* L)
+ {
+ luax_newtype(L, TYPE_JSL, f);
+ return 0;
+ }
+}
+} \ No newline at end of file