test some stuff
This commit is contained in:
@@ -27,9 +27,8 @@ void moduleColor(scriptcontext_t *context) {
|
||||
lua_pushstring(context->luaState, "__tostring");
|
||||
lua_pushcfunction(context->luaState, moduleColorToString);
|
||||
lua_settable(context->luaState, -3);
|
||||
|
||||
lua_pop(context->luaState, 1);
|
||||
}
|
||||
lua_pop(context->luaState, 1);
|
||||
|
||||
lua_register(context->luaState, "color", moduleColorFuncColor);
|
||||
lua_register(context->luaState, "colorRainbow", moduleColorRainbow);
|
||||
|
||||
@@ -46,6 +46,21 @@ int moduleTilesetIndex(lua_State *l) {
|
||||
} else if(stringCompare(key, "texture") == 0) {
|
||||
lua_pushstring(l, ts->image);
|
||||
return 1;
|
||||
} else if(stringCompare(key, "tileWidth") == 0) {
|
||||
lua_pushnumber(l, ts->tileWidth);
|
||||
return 1;
|
||||
} else if(stringCompare(key, "tileHeight") == 0) {
|
||||
lua_pushnumber(l, ts->tileHeight);
|
||||
return 1;
|
||||
} else if(stringCompare(key, "tileCount") == 0) {
|
||||
lua_pushnumber(l, ts->tileCount);
|
||||
return 1;
|
||||
} else if(stringCompare(key, "columns") == 0) {
|
||||
lua_pushnumber(l, ts->columns);
|
||||
return 1;
|
||||
} else if(stringCompare(key, "rows") == 0) {
|
||||
lua_pushnumber(l, ts->rows);
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_pushnil(l);
|
||||
|
||||
@@ -13,21 +13,20 @@ void moduleTime(scriptcontext_t *ctx) {
|
||||
|
||||
// Script structure
|
||||
if(luaL_newmetatable(ctx->luaState, "time_mt")) {
|
||||
// Metatable is new, set __index
|
||||
lua_pushstring(ctx->luaState, "__index");
|
||||
lua_pushcfunction(ctx->luaState, moduleTimeIndex);
|
||||
lua_settable(ctx->luaState, -3);
|
||||
lua_setfield(ctx->luaState, -2, "__index");
|
||||
}
|
||||
lua_pop(ctx->luaState, 1);
|
||||
|
||||
// Global time struct
|
||||
lua_pushlightuserdata(ctx->luaState, &TIME);
|
||||
dusktime_t **ud = (dusktime_t**)lua_newuserdatauv(
|
||||
ctx->luaState, sizeof(dusktime_t*), 0
|
||||
);
|
||||
*ud = &TIME;
|
||||
luaL_setmetatable(ctx->luaState, "time_mt");
|
||||
lua_setglobal(ctx->luaState, "TIME");
|
||||
}
|
||||
|
||||
int moduleTimeIndex(lua_State *L) {
|
||||
assertNotNull(L, "Lua state cannot be NULL.");
|
||||
|
||||
const char_t *key = lua_tostring(L, 2);
|
||||
assertStrLenMin(key, 1, "Key cannot be empty.");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user